| 127 | |
| 128 | In !HeuristicLab we need to define the problem and choose an algorithm with which we can optimize it. |
| 129 | |
| 130 | === Defining the problem === |
| 131 | We need to create a new External Evaluation Problem, so switch to the Clipboard (View > Clipboard if it is not visible) and click the yellow plus icon to add a new item. Type "external" without quotes in the search box and you'll find the right item called "External Evaluation Problem". Double click on it and you'll see it added to the clipboard. Double click it again in the clipboard so that we can edit it. |
| 132 | |
| 133 | In the box you can type a Name, I'll use "!AnyLogic Supply Chain Problem". You can also double click the information icon on the right end of the name box to edit the description. |
| 134 | |
| 135 | In the Parameters box you'll see a number of different parameters. Let's configure the client first. |
| 136 | |
| 137 | ==== Client ==== |
| 138 | Click on the parameter called "Client" to which currently an `EvaluationServiceClient` is attached and you'll see another box with parameters. Among those is one called "Channel" which is currently null, meaning that it has no value defined. Click on Channel and then click on the pencil icon to give it a value. Choose the `EvaluationTCPChannel` by double clicking it in the emerging dialog. Now type the IP Address of the computer where the simulation will run ("127.0.0.1" in case it will be run on the same computer) and enter the port number (remember we chose "2112" above). Okay we're done with the client. |
| 139 | |
| 140 | Next we'll configure the parameter Evaluator. Click on this parameter to get its list of parameters. |
| 141 | |
| 142 | ==== Evaluator ==== |
| 143 | In the "Collected values" section click on the yellow plus icon and add a `LookupParameter<T>` and for `T` choose an `IntegerVector` by double clicking on it (may take a couple of seconds). Name this parameter "!IntegerVector", as always without quotes, and click Ok. Remember what you entered as Name! |
| 144 | |
| 145 | So we're done with this parameter. The next one is Maximization which we'll not need to touch as it is already false (we're minimizing costs). So we get to the parameter "Operators" by clicking on it. |
| 146 | |
| 147 | ==== Operators ==== |
| 148 | By clicking on the yellow plus button add following operators from the !HeuristicLab.Encodings.!IntegerVectorEncoding namespace: |
| 149 | * `SinglePointCrossover` |
| 150 | * `UniformOnePositionManipulator` |
| 151 | |
| 152 | If you click on the just added `UniformOnePositionManipulator` you'll see two more parameters called Maximum and Minimum. We can either add a value to them here, or add a parameter at a higher level (e.g. at the problem level). So let's add two `ValueParameter<T>` and choose `IntValue` for `T`. Name one of them "Minimum" and the other "Maximum". Choose the value 1 for Minimum and 100 for Maximum. |
| 153 | |
| 154 | Now click on and configure the last parameter called !SolutionCreator |
| 155 | |
| 156 | ==== !SolutionCreator ==== |
| 157 | Click the yellow plus icon and add a `UniformRandomIntegerVectorCreator`. Click on it to see its parameters. You'll note there is an additional one called "Length". Let's add a new `ValueParameter<T>` just like Minimum and Maximum but called Length to the problem's parameters and give it the value 6, because we have six parameters to optimize. You should save the clipboard now to save the problem within it (you can also save the problem to a separate file if you want). |
| 158 | |
| 159 | === Choosing an Algorithm === |
| 160 | |
| 161 | We're now done with the problem. We have added a crossover operator and a mutator so we're somewhat limited to a Genetic Algorithm or one of its variants. Algorithms like Tabu Search need more complex operators. |
| 162 | |
| 163 | So create a new Genetic Algorithm by choosing "New" from the File menu. |
| 164 | |
| 165 | Drag the problem from the clipboard onto the problem tab of the GA that we have just created. Go to the parameters tab and select the mutator that we have added (no mutator is chosen by default). |
| 166 | |
| 167 | == Optimizing the model == |
| 168 | |
| 169 | Now it's time, we're ready to start the optimization. First switch back to !AnyLogic 6 and start the !HeuristicLabOptimizationExperiment. Click on the button "Run Experiment" to set it into listening mode. |
| 170 | |
| 171 | Go to !HeuristicLab and click the green arrow at the bottom to start the algorithm. |
| 172 | |
| 173 | Now in the back the algorithm attempts a TCP connection to the given IP Address and port and exchanges parameters with the simulation model. It will receive quality values and use these to determine the fitness of its solutions. |