question

Pablo C4 avatar image
0 Likes"
Pablo C4 asked Pablo C4 commented

can i set the number of instances as a parameter?

Hello,

a collegue built her model using an operator as a template and then the other operators are instances so they share the same processflow. now she's setting up experimenter and is not sure how can you set up the number of instances of that operator as a parameter for the experiment.

any idea how to preceed?..

thanks in advance.. regards

Pablo

FlexSim 22.0.4
parameters tableinstancestemplates
5 |100000

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

1 Answer

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Pablo C4 commented

Option 1:

Add the template operator to a group, set that group as reference in the parameter and choose 'Delete and Copy Group Members' in the On Set trigger. The extra operators won't be instances of the template but complete copies of the original operator though.

1658303978180.png

Option 2:

If properties of the template are changed and it is thus important that the extra operators are instances rather than copies, you can set the reference to the template operator and use the following code in the On Set trigger.

if(isReset)
{
    // Delete previous instances
    treenode instances = reference.find(">templateinstances");
    if(objectexists(instances))
    {
        while(instances.subnodes.length > 0)
        {
            instances.find("/1+/~").destroy();
        }
    }

    // Create instances until value is reached
    for(int index = 2; index <= newValue; index++)
    {
        Object template = reference;
        Array loc = template.getProperty("Location");
        Object newInstance = applicationcommand("maketemplateinstance", template, template.up, loc);
        applicationcommand("checkcreatetemplateinstancesoncreate", template);
        newInstance.name = template.name + "_" + string.fromNum(index, 0);
    }
}

instance_parameter_fm.fsm


· 2
5 |100000

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

Pablo C4 avatar image Pablo C4 commented ·

thanks, indeed, we needed the operators to be instances instead of copiesm so option 2 seems to do the trick

regards

Pablo

0 Likes 0 ·
Jordan Johnson avatar image Jordan Johnson ♦♦ commented ·

Option 3:You can modify the Delete and Copy Objects code to delete down to 2, rather than 1, and then copy the second object, which is an instance. This avoids using applicationcommand(), but creates a minimum of 2 rather than 1:

{ // ************* PickOption Start ************* //
/***popup:ParamSetNodeValue*/
/**Delete and Copy Group Members*/
if (/***tag:condition*//**/isReset/**/) {
  Array objects = reference.as(Group).toFlatArray();
  
  if (objects.length < 2) {
    mpt("Error setting parameter " + c.up.up.name + " - Not enough objects in object set"); mpr();
  } else {
    for (int i = 3; i <= objects.length; i++) {
      objects[i].destroy();
    }
    
    treenode firstObj = objects[2];
    int total = Math.max(1, newValue);
    for (int i = 3; i <= total; i++) {
      treenode newObj = createcopy(firstObj, firstObj.up);
      newObj.name = firstObj.name + "_" + i;
      applicationcommand("recreateObjectConnections", newObj, firstObj);
    }
  }
}

} // ******* PickOption End ******* //
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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