How to use stopDelay(agent) on AnyLogic - simulation

I am generating multiple agents at the source. I would like to let them wait until some event.
I am trying to access the "delay.stopDelay(agent)" however it requires an agent as a parameter.
How should I proceed?

Here is the answer:
Tasks t = null;
if(delayTasks.size()>0){
//use a random agent stored at delayTasks
int i = uniform_discr(0, delayTasks.size()-1);
t=delayTasks.get(i);
//or use any specific condition
for(int i=0; i< delayTasks.size(); i++){
//if() any condition
t=delayTasks.get(i);
}
//Then you release the agent t
if(...){
delayTasks.stopDelay(t);
}
}

Related

remove agent from assembler queue part

I have a problem with my code in Anylogic. I would like to remove/delete the agents in the assembler with a button. If the agents are in the delay part of the assembler I can remove them (that's where my code works). However, the agents that are in the queue contains part of the assembler are not deleted. I used the following code in my button's action field, but when I click the button, the stocks in the queue part of the assembler remain. Does anyone know a solution for this?
Picture of my model in Anylogic
My code to remove/delete the agents from the queue part of the assembler:
while(Lager_Oberteile.size() > 0) {
Agent agent = Lager_Oberteile.removeFirst();
}
while(Lager_Plättchen.size() > 0) {
Agent agent = Lager_Plättchen.removeFirst();
}
if (Klebestation.queueSize(1) > 0) {
Agent agent = Klebestation.queueGet(1, 0);
Klebestation.remove(agent);
}
if (Klebestation.queueSize(2) > 0) {
Agent agent = Klebestation.queueGet(2, 0);
Klebestation.remove(agent);
}
if (Klebestation.delaySize() == 1) {
Agent agent = Klebestation.delayGet(0);
Klebestation.remove(agent);
}
offene_Aufträge = 0;
Stopp1.unblock();
Stopp2.unblock();
You can remove all agents in the queue using:
int numAgents = assembler.queue1.size();
for (int i=0; i<numAgents; i++) {
assembler.queue1.remove(0);
}
You may be confused because the visual counter will not jump back to zero:
However, this only shows how many agents have entered that queue. You can always test such things with tracelns:
So use the code for all 5 queues and you are good.

Why can't I create a pointer to a TTreeNode in a TTreeView

Using C++ Builder in Rad Studio 10.4
Why can't I create a pointer to a TTreeNode?
I have a TTreeView called BookmarksTree, and I want to loop through all of its nodes. When I try and compile this:
TTreeNode *Node;
Node = BookmarksTree->Items[1];
I get a compiler error:
assigning to 'Vcl::Comctrls::TTreeNode *' from incompatible type 'Vcl::Comctrls::TTreeNodes'
According to Vcl.ComCtrls.TCustomTreeView.Items, I should be able to use
MyTreeNode = TreeView1->Items[[1]];
Has anyone any idea what's wrong here?
BookmarksTree->Items is a pointer to a single TTreeNodes object. You are trying to perform pointer arithmetic to access a node as if the Items were an array of TTreeNode* pointers, which is simply not the case.
You need to use the TTreeNodes::Item[] sub-property instead, eg:
int count = BookmarksTree->Items->Count;
for(int i = 0; i < count; ++i)
{
TTreeNode *Node = BookmarksTree->Items->Item[i];
...
}
Alternatively, you can use the TTreeNodes::operator[], but that requires you to dereference the TTreeNodes* pointer first, eg:
int count = BookmarksTree->Items->Count;
for(int i = 0; i < count; ++i)
{
TTreeNode *Node = (*(BookmarksTree->Items))[i];
...
}
Alternatively, in the Clang-based compilers only, you can use C++ iterators, per C++ Iterator Support for Delphi Enumerable Types and Containers, eg:
auto iter = std::begin(BookmarksTree->Items);
auto end = std::end(BookmarksTree->Items);
while (iter != end)
{
TTreeNode *Node = *iter++;
...
}
Or a range-for loop (which uses iterators internally):
for(TTreeNode *Node : BookmarksTree->Items)
{
...
}

How to do simple javascript looping in protractor

for ( i = 0; i < 100; i++) {
browser.manage().logs().get('browser').then(function(browserLog) {
console.log(i);
});
}
I am trying to run this using protractor, but i get hundred times 100 printed in console. I have some functionality which am trying to implement using looping.How can i do looping in protractor?
This is because the functions you're passing to then all close over the variable i, not the value that variable has when you create the functions. So later, when the functions are called, they all see the value of i as it is then, after the loop is complete (100).
If you want to capture the value of i as it is when you create the function, you can use ES5's Function#bind:
for ( i = 0; i < 100; i++) {
browser.manage().logs().get('browser').then(function(index, browserLog) {
console.log(index);
}.bind(null, i));
}
bind returns a new function that, when called, will call the original function with a given this value (in this case I'm using null) and any arguments you follow that with, followed by arguments given to the function bind returned.
Another approach is a builder function:
for ( i = 0; i < 100; i++) {
browser.manage().logs().get('browser').then(buildHandler(i));
}
function buildHandler(index) {
return function(browserLog) {
console.log(index);
};
}
That has the advantage of allowing the caller to control this.

Google Apps Script Trigger not running

I have trouble with a time based trigger, which installs another time based trigger after work. I use this concept to split the work. Unfortunately the installed trigger never runs, but it is created.
The following code illustrates the concept:
function start() {
installTrigger();
}
function installTrigger(){
deleteClockBasedTriggers();
ScriptApp.newTrigger("sendMail").timeBased().after(5000).create();
}
function deleteClockBasedTriggers(){
var projectTriggers = ScriptApp.getProjectTriggers();
for(var i=0; i<projectTriggers.length; i++){
if(projectTriggers[i].getEventType() == ScriptApp.EventType.CLOCK){
ScriptApp.deleteTrigger(projectTriggers[i]);
}
}
}
function sendMail(){
var email = "xyz#gmail.com";
MailApp.sendEmail(email, "TriggerMail", "hello");
installTrigger();
}
You need to set trigger after 1 minute to get it fired.

A GMail Script to unstar email loop

I have emails in my inbox and ones that get archived throughout the day. Every night I want to create a script to automatically unstar them for the next day. I created this script but it doesn't seem to work. The Google docs don't seem to be much help in the way of syntax.
Here is the code I was using. Will this code access the archive as well?
function processInbox() {
var threads = GmailApp.getInboxThreads();
for (var i = 0; i < threads.length; i++) {
var firstThread = GmailApp.getInboxThreads(0,1)[0];
var message = firstThread.getMessages()[0];
GmailApp.unstarMessage(message);
}
};
You are working only on the first thread in your inbox.
GmailApp.getInboxThreads(0,1)[0];
You needed to put your 'i' variable in that line in order to iterate on the messages.
Try something like that:
// first limit the script for the top 50 emails (or a bit more) but don't run on ALL of them -it's not efficient.
var threads = GmailApp.getInboxThreads(0, 50);
for (var i = 0; i < threads.length; i++) {
var message = threads[i].getMessages()[0];
GmailApp.unstarMessage(message);
}
Good luck.