# Changes between Version 2 and Version 3 of Documentation/Howto/OptimizeAnyLogicModels

Ignore:
Timestamp:
04/26/11 22:17:41 (10 years ago)
Comment:

tbc

### Legend:

Unmodified
 v2 Next we need to go to the "Advanced" section of the properties and configure the experiment loop: perform the parameter retrieval, run the simulation, send the quality back, reset the model and continue with another attempt of retrieving parameters. In the "Imports:" section enter following code: The following code samples need to be entered into the respective boxes. ==== Imports ==== {{{ #!java }}} In the "Additional class code:" section enter following code: ==== Additional class code ==== {{{ #!java We have defined a method //getMessage()// that calls our library to get the next message from !HeuristicLab and extract the parameters. You'll notice that here I have put the same text as before in the box "Expression" which is an intentional coincidence ;-) Now in the section "Initial experiment setup" we need to initialize our communication driver. Paste the following code: ==== Initial experiment setup ==== {{{ #!java The number '''2112''' is important as it is the TCP port that our service will be listening on. This must be reachable by !HeuristicLab through a network connection (yes this means you can run !HeuristicLab on a different computer than your simulation model). You can of course choose another port (basically any number from 1 to 65535, but some numbers like 80 might be used by another application already). In the next section "Before each experiment run" we need to initialize our variables that store the quality and replications and we need to fetch the new parameters. Past the following code: ==== Before each experiment run ==== {{{ #!java The call to //getMessage()// will block, that means the simulation will wait here, until we have received a new set of parameters. We can leave the next section "Before simulation run" empty, but in the section after that, called "After simulation run" we need to paste following code: ==== Before simulation run ==== leave this empty ==== After simulation run ==== {{{ #!java This calls the cost function in the Main object called //meanDailyCost()// in this case. This is the target that we want to optimize (note that we add an increasing penalty term if the customer waiting time is above a certain level). Finally in the section "After iteration" we calculate the mean cost among all iterations performed and send that back to !HeuristicLab: ==== After iteration ==== {{{ #!java }}} We are done here. Save the model. You can now start the !HeuristicLabOptimizationExperiement, although of course it won't do anything but block until it receives parameters. This sends the mean quality of the (possible) replications back to !HeuristicLab. We are done here. Save the model. You can now start the !HeuristicLabOptimizationExperiement, although of course it won't do anything but block until it receives parameters. == Preparing the Optimization Problem in !HeuristicLab 3.3 ==