question

Bryan Suharik avatar image
0 Likes"
Bryan Suharik asked Bryan Suharik answered

Assign Operators by Code

Hello,

I have a model that uses a GUI to build the entire model. Because of this, i need quite a bit of flexibility. First, I have the model build processes based on how many the user defines. I also ask the user to choose how many operators the model will have. Based on how many are chosen, the model builds the operators.

I need to assign these operators to all the processors and have the number of processors for the process dependent on item from a global table lookup.

//Builds the operators
for (int ops=1; ops<=MTs; ops++) { 
    createinstance(node("taskexecuters/Operator", library()), model()); 
    treenode Mechanic = last(model());
    setloc(Mechanic, ops,-10,0); 
    setname(Mechanic, concat("Mechanic", numtostring(ops,0,0)));
}

Then I have all the processors built and need the above operators Center attached to all the processors, but only some operators are called depending on the item type in that process.

createinstance(node("/fixedresources/Processor", library), model());

treenode bayrepair = last(model());
setname(bayrepair, "BayRepair");
setloc(bayrepair, 0, y, 0);

contextdragconnection(Checkin, bayrepair, "A"); 
string ProcessTime =
    "treenode current =ownerobject(c); treenode item = parnode(1); return gettablenum(\"ProcessTimes\",getitemtype(item),2);"; 
setvarstr(bayrepair, "cycletime", ProcessTime);
setvarnum(bayrepair, "nrofprocessoperators", gettablenum("ProcessTimes", getitemtype(item), 3));
contextdragconnection(mechanic, bayrepair, "S");

Basically, via code, I need to assign all the operators in the model to all the processors, but only some operators are called for work depending on the item type that is formatted from the global table.

Thanks for the help! I'm a bit new to this programming and FlexSim, but hope to be able to give help soon!

FlexSim 16.0.6
codeoperatorsprocessoperators assignmentautobuild
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ben Wilson avatar image Ben Wilson ♦♦ commented ·

I edited the question to:

  • format the code into visual code blocks
  • rename the "o" variable to "ops"
  • added the ops index to the setname() call so that all Mechanics will have a unique name
0 Likes 0 ·
Bryan Suharik avatar image
1 Like"
Bryan Suharik answered

I figured it out on combining the string and loop num. Also, using the dispatcher to conduct the tasks helped!

for (int p = 1; p<=MTs;p=p+1)

{

string bayn = numtostring(p,0,0);

string bayn2 = concat("/Mechanic ",bayn);

contextdragconnection(Dispatch,node(bayn2,model()),"A");

}

for (int q = 1; q<=BAYNUMBER;q=q+1)

{

string disbay = numtostring(q,0,0);

string disbay2 = concat("/Repair Bay ", disbay);

contextdragconnection(Dispatch, node(disbay2,model()), "S");

}

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Joerg Vogel avatar image
1 Like"
Joerg Vogel answered Ben Wilson commented

hmm, you should use names for variable's with more than one character. Some characters are functions or operators in the source code of Flexsim's engine. In really young versions of Flexsim there exited the operator "o". I don't know if the operator has got a function or it is still in use.

Then you should give names to objects with unique names. In the creation of your mechanics you give them all the same name. You can concatenate the name with a number string op_name = concat("Mechanic",numtostring(o,0,0));// "o" should still be named different.

If you call more than one operator to assist a processor you connect the centerport connection to a dispatcher and connect the operators from the dispatcher to them by an object connection "a". A fixed resource can only call directly one operator by a center port connection. And the call isn't linked to the name of the operator. It is linked to a pointer, which is unique to each object in the model even if the name is the same. If you like you can test it on your own. You can set a flowitem to be the selected object so() and write in the script console pf(tonum(so())); If you open an output console and execute the script console the number you see in the output console is different for each different item you select as so().

@Bryan Suharik

· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Matt Long avatar image Matt Long commented ·

You don't have to worry about writing variables that may have been functions or "special" values used by the engine. Once you declare a variable, it overrides whatever that character or word used to mean. You can see this often with c, i, count which are commonly used as variables but which also have special meaning when used in certain ways.

1 Like 1 ·
Ben Wilson avatar image Ben Wilson ♦♦ Matt Long commented ·

Though you can still have problems if you declare a Global Macro with the same name as a variable used elsewhere, so caution in your naming collisions is still warranted.

1 Like 1 ·
Bryan Suharik avatar image Bryan Suharik commented ·

Will do, thanks for the tip!

0 Likes 0 ·