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.

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

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.

  1. createinstance(node("/fixedresources/Processor", library), model());
  2.  
  3. treenode bayrepair = last(model());
  4. setname(bayrepair, "BayRepair");
  5. setloc(bayrepair, 0, y, 0);
  6.  
  7. contextdragconnection(Checkin, bayrepair, "A");
  8. string ProcessTime =
  9. "treenode current =ownerobject(c); treenode item = parnode(1); return gettablenum(\"ProcessTimes\",getitemtype(item),2);";
  10. setvarstr(bayrepair, "cycletime", ProcessTime);
  11. setvarnum(bayrepair, "nrofprocessoperators", gettablenum("ProcessTimes", getitemtype(item), 3));
  12. 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.

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.