question

Tristan D avatar image
0 Likes"
Tristan D asked Clair A edited

How to automatically create variables for OptQuest ?

I am currently trying to automatically create variables (located in the Tree at "Tools/Experimenter/ExperimentVariables") using Flexscript code before launching OptQuest. For the moment, I manage to create treenodes in the good place but :

-I am not able to write in those treenodes as it can automatically know where the associated variables are. I want it to be written in the treenode named "Variable".

-I am not able to change de variable type : Permutation, Discrete,.....

Table current = param(1); //Table node


int sizerow2 = Table("BDD_Reconst").numRows ;

/**Ecriture des variables*/

for (int i = 1; i <= sizerow2; i++) {
	string istr = numtostring(i);
	Model.find("Tools/Experimenter/ExperimentVariables").subnodes.add();
	Model.find("Tools/Experimenter/ExperimentVariables").last.name = "Variable "+istr;

	/**Création des dossiers dans la variable*/

	treenode vari = Model.find("Tools/Experimenter/ExperimentVariables").last;
	vari.subnodes.add();
	vari.last.name = "Variable";
	vari.subnodes.add();
	vari.last.name = "Scénario 1";
}
Choose One
flexscriptoptquesttreenode
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

Clair A avatar image
4 Likes"
Clair A answered Clair A edited

OptQuest variables are created in the first tab Scenarios of the Experimenter, when you click on this "+" button:

What is the code behind the scene of this button ?

One trick is to right-click in a blanck space of the tab and go to View > Explore structure:

This allows you to browse the tree view of the graphical user interface of this tab. Inside the Scenarios node, there is a node called AddVariable, which is the "+" button. Inside its attributes, you will find a node called OnPress. The code of this node is executed when you press the "+" button. At line 6 you will notice that it calls a function called addNewExpVar:

Which is defined in the node up OnPress. The source code is available:

So you can copy/paste and adapt this code in your own logic to automatically create experimenter variables.

You can use the same trick to find how to change the type of a variable in the optimizer design.

When you click on the cell of a variable type, there is a pop-up menu to choose the variable type:

Where is the code behind the scene ?

Right-click in the table area, go to View > Explore Structure:

And you will find a node called menupopup with the code executed behind each option of this menu:

You can then copy/paste and adapt this code in your own logic to automatically change the variable type.


5 |100000

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