moving deprecated to another branch
|
@ -1,14 +0,0 @@
|
||||||
# Overview of the Bonsai Connector for AnyLogic
|
|
||||||
The Bonsai Connector is a library add-in to AnyLogic that allows users to connect their AnyLogic models to the Microsoft Bonsai platform.
|
|
||||||
|
|
||||||
After downloading the <a href="https://www.anylogic.com/features/artificial-intelligence/microsoft-bonsai/">wrapper</a> from AnyLogic, check out the <a href="connector/wrapper_model_workflow.pdf">wrapper model workflow</a> document to learn more about incorporating it with your own model.
|
|
||||||
|
|
||||||
There are a number of samples packaged with the connector:
|
|
||||||
|
|
||||||
- <a href="samples/abca">Activity Based Costing</a> - a simplified factory floor model for cost associated with product processing is calculated and analyzed.
|
|
||||||
- <a href="samples/product-delivery">Product Delivery</a> - simulates product delivery between three manufacturing facilities and fifteen distributors in the USA.
|
|
||||||
|
|
||||||
|
|
||||||
## Microsoft Open Source Code of Conduct
|
|
||||||
|
|
||||||
This repository is subject to the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct).
|
|
Двоичные данные
deprecated/connector/BonsaiLibrary.jar
Двоичные данные
deprecated/connector/BonsaiLibrary_v2.6.jar
|
@ -1,133 +0,0 @@
|
||||||
# Bonsai Connector Library
|
|
||||||
The library will need to be included with your <a href="https://www.anylogic.com/features/artificial-intelligence/microsoft-bonsai/">wrapper</a>. While the <a href="wrapper_model_workflow.pdf">wrapper model workflow</a> outlines what needs to be included in your AnyLogic model, this document describes the classes that are used in the connector library and how they map to your inkling code code for Bonsai.
|
|
||||||
|
|
||||||
The Bonsai Connector includes base functionality for communicating to the Microsoft Bonsai service, and does not require the user to implement any special logic to do so. The connector includes three base classes that are used to implement connection to the Bonsai platform.
|
|
||||||
|
|
||||||
- Config class
|
|
||||||
- Observation class
|
|
||||||
- Action class
|
|
||||||
|
|
||||||
When your simulator connects to the Bonsai platform, it does so by:
|
|
||||||
|
|
||||||
1. Registering your simulator with the Bonsai platform using the Simulator Name specified in the connector. After starting your simulator, click on the Train button in the Bonsai dashboard and select the name of your simulator to begin training.
|
|
||||||
2. Upon an *episode start* event, the connector acquires an initial configuration from the Bonsai brain. This is used by a class derived from **Config** to set initial conditions for your model and map to the values in your Config type in inkling. You can learn more about configuring lessons in inkling <a href=
|
|
||||||
https://docs.microsoft.com/en-us/bonsai/inkling/">here</a>.
|
|
||||||
3. At each *episode step* in your model the connector sends the values derived from the **Observation** class. The values in your derived Observation class should match the name and types of variables found in the State type in your inkling for your Bonsai brain. When the brain receives the observation, it also evaluates the reward or terminal conditions associated with your inkling and determines the next best action.
|
|
||||||
4. During the *episode step* event, the connector provides the values from a derived **Action** class. These values map to the Action type in your inkling for your Bonsai brain and represent the next step, or action, the brain would like your model to run.
|
|
||||||
5. If a terminal condition is hit in inkling, or your simulator reaches a halted state, the connector will fire an *episode finish* event. This is a great place to stop your model and get it ready for a new run.
|
|
||||||
|
|
||||||
|
|
||||||
## The Config class
|
|
||||||
The Config class is used to define the values that the Bonsai brain will use during an episode start event. These allow you to create a machine teaching curriculum for your brain. For more on curriculums, see [here].
|
|
||||||
|
|
||||||
An example of a derived Config class is:
|
|
||||||
|
|
||||||
```java
|
|
||||||
import com.anylogic.sdk3.connector.Config;
|
|
||||||
|
|
||||||
public class ModelConfig extends Config {
|
|
||||||
public double arrivalRate;
|
|
||||||
public double existenceCostPH;
|
|
||||||
public double resABusyCostPH;
|
|
||||||
public double resAIdleCostPH;
|
|
||||||
public double resBBusyCostPH;
|
|
||||||
public double resBIdleCostPH;
|
|
||||||
public double relativeProcessCost;
|
|
||||||
public double relativeMoveCost;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
The values in your Config class should map to the config type values in inkling. For example, using the values above, you would also have:
|
|
||||||
|
|
||||||
```
|
|
||||||
type SimConfig {
|
|
||||||
arrivalRate: number,
|
|
||||||
existenceCostPH: number,
|
|
||||||
resABusyCostPH: number,
|
|
||||||
resAIdleCostPH: number,
|
|
||||||
resBBusyCostPH: number,
|
|
||||||
resBIdleCostPH: number,
|
|
||||||
relativeProcessCost: number,
|
|
||||||
relativeMoveCost: number,
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
defined in your inkling for your brain in Bonsai.
|
|
||||||
|
|
||||||
|
|
||||||
## The Observation class
|
|
||||||
The Observation class is used to define the class that will be using to communicate the state of the AnyLogic model to the Bonsai brain. As outlined above, these values are used by the brain to evaluate reward and terminal conditions as well as what action the model should take next. An example of a derived Observation class is:
|
|
||||||
|
|
||||||
```java
|
|
||||||
import com.anylogic.sdk3.connector.Observation;
|
|
||||||
|
|
||||||
public class ModelObservation extends Observation {
|
|
||||||
public double arrivalRate;
|
|
||||||
public int nResA;
|
|
||||||
public int nResB;
|
|
||||||
public double utilResA;
|
|
||||||
public double utilResB;
|
|
||||||
public double idleCostResA;
|
|
||||||
public double idleCostResB;
|
|
||||||
public double busyCostResA;
|
|
||||||
public double busyCostResB;
|
|
||||||
public double processTime;
|
|
||||||
public double conveyorSpeed;
|
|
||||||
public double costPerProduct;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
The values in your Observation class should map to the state type values in inkling. For example, using the values above, you would also have:
|
|
||||||
|
|
||||||
```
|
|
||||||
type SimState {
|
|
||||||
arrivalRate: number<0.5 .. 2.0>,
|
|
||||||
nResA: Number.Int32<1 .. 20>,
|
|
||||||
nResB: Number.Int32<1 .. 20>,
|
|
||||||
utilResA: number,
|
|
||||||
utilResB: number,
|
|
||||||
idleCostResA: number<0.1 .. 20>,
|
|
||||||
idleCostResB: number<0.1 .. 20>,
|
|
||||||
busyCostResA: number<0.1 .. 20>,
|
|
||||||
busyCostResB: number<0.1 .. 20>,
|
|
||||||
processTime: number<1.0 .. 12.0>,
|
|
||||||
conveyorSpeed: Number.Int32<0 .. 15>,
|
|
||||||
costPerProduct: number<1.0 .. 15.0>,
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
defined in your inkling for your brain in Bonsai.
|
|
||||||
|
|
||||||
> It is a recommended best practice to indicate the ranges of your states in inkling. This will increase the speed of your brain training.
|
|
||||||
|
|
||||||
## The Action class
|
|
||||||
The Action class is used to define the class that will be using to parse the action from the Bonsai brain to be performed in the AnyLogic model. This may include As outlined above, these values are used by the brain to evaluate reward and terminal conditions as well as what action the model should take next. An example of a derived Observation class is:
|
|
||||||
|
|
||||||
```java
|
|
||||||
import com.anylogic.sdk3.connector.Action;
|
|
||||||
|
|
||||||
public class ModelAction extends Action {
|
|
||||||
public int nResA;
|
|
||||||
public int nResB;
|
|
||||||
public double processTime;
|
|
||||||
public double conveyorSpeed;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
The values in your Action class should map to the action type values in inkling. For example, using the values above, you would also have:
|
|
||||||
|
|
||||||
```
|
|
||||||
type Action {
|
|
||||||
nResA: number<1 .. 20>,
|
|
||||||
nResB: number<1 .. 20>,
|
|
||||||
processTime: number<1.0 .. 12.0>,
|
|
||||||
conveyorSpeed: number<1.0 .. 15.0>,
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
defined in your inkling for your brain in Bonsai.
|
|
||||||
|
|
||||||
> It is a recommended best practice to indicate the ranges of your actions in inkling. This will increase the speed of your brain training.
|
|
||||||
|
|
||||||
# v2.6 notes
|
|
||||||
|
|
||||||
- Introduces the ability to have the initial start event, or not. This is useful depending on whether your simulator is event or time based.
|
|
||||||
- Adds the ability to edit the timeout to Bonsai
|
|
||||||
- Resolves issue with animated experiments training for long durations
|
|
Двоичные данные
deprecated/connector/wrapper_model_workflow.pdf
Двоичные данные
deprecated/images/add_sim.png
До Ширина: | Высота: | Размер: 163 KiB |
Двоичные данные
deprecated/images/add_sim_al_nozip.png
До Ширина: | Высота: | Размер: 81 KiB |
Двоичные данные
deprecated/images/add_sim_al_zip.png
До Ширина: | Высота: | Размер: 66 KiB |
Двоичные данные
deprecated/samples/abca/ABCA-Optimization-Writeup.docx
|
@ -1,10 +0,0 @@
|
||||||
#from JRE
|
|
||||||
FROM openjdk:8-jre-alpine
|
|
||||||
|
|
||||||
# required for fonts in AL models
|
|
||||||
RUN apk --update add fontconfig ttf-dejavu
|
|
||||||
|
|
||||||
COPY ./exported.zip .
|
|
||||||
RUN unzip -q exported.zip
|
|
||||||
|
|
||||||
CMD find -name '*_linux.sh' -exec sh {} \;
|
|
|
@ -1,118 +0,0 @@
|
||||||
# Activity Based Costing Analysis Overview
|
|
||||||
In this simplified factory floor model, cost associated with product processing is calculated and analyzed.
|
|
||||||
|
|
||||||
Each incoming product seizes one unit of resource A, then one unit of resource B, then is processed by a machine. Afterwards, A is released, the product is conveyed to the exit, and then B is released just before the exit.
|
|
||||||
|
|
||||||
Whenever the product is in the system, the “Existence” cost applies ($ per hour). While a resource unit is being seized by a product, its “Busy” cost is allocated to the product, otherwise the “Idle” cost is applied (which is uniformly distributed to all products). Processing at the machine and conveying have direct fixed costs, which are different for equipment with different performances.
|
|
||||||
|
|
||||||
Cost accumulated by a product is broken down into several categories for analysis and optimization. You can change the factory floor parameters on the fly and see how they affect the product cost.
|
|
||||||
|
|
||||||
### Complexity
|
|
||||||
- Production rate, cost of resources A & B are configurable.
|
|
||||||
- Capacities of resource A, B, processing time of the machine and conveyor speed can be adjusted dynamically in order to keep the total cost per product at minimum.
|
|
||||||
- Regular simulation optimization (SO) is not capable of adaptive change of parameters in order to produce optimum results over time
|
|
||||||
|
|
||||||
### Observation space
|
|
||||||
Although there are many aspects of the simulator, the `arrival rate` is what is used to by the brain to make decisions.
|
|
||||||
|
|
||||||
|
|
||||||
### Action space
|
|
||||||
- Number of resource A and B
|
|
||||||
- process time, conveyor speed (these could be continuous values)
|
|
||||||
|
|
||||||
### Reward
|
|
||||||
- The reward is optimized based on minimizing the total cost per product (this may need modification to maintain a desired production goal in a particular scenario).
|
|
||||||
|
|
||||||
# Create a Brain
|
|
||||||
|
|
||||||
To start a new brain for this model:
|
|
||||||
|
|
||||||
1. Create an account or sign into Bonsai.
|
|
||||||
2. Click **Create brain** button in the top left, then select **Empty brain** in the dialog.
|
|
||||||
3. Name your new brain (e.g., “costing-analysis”).
|
|
||||||
4. Click **Create Brain**. This will create a new brain for you.
|
|
||||||
|
|
||||||
Copy the contents of <a href="abca.ink">abca.ink</a> in to the *Teach* tab for your new brain.
|
|
||||||
|
|
||||||
Do not click Train yet.
|
|
||||||
|
|
||||||
# Running the Model
|
|
||||||
|
|
||||||
To run the model, right click on **AnimatedExperiment** then click the **Run** button. You will see text in the console about registering with the Bonsai platform. Once registration is complete (it will only take a few seconds), go back to the Bonsai UI where you created your brain.
|
|
||||||
|
|
||||||
Click the **Train** button. The simulator with the name matching your simulator will appear (in the example above, this is called *AnyLogic - ABCA*). Click the name of your simulator.
|
|
||||||
|
|
||||||
If this is the first start of your brain it may take a few minutes for the brain to generate the appropriate parameters and connect to the simulator. Once the connection is made you will see your first episodeStart event fire in the ModelExecuter handler.
|
|
||||||
|
|
||||||
You may decide to let your training run for a bit, particularly across multiple episode start events, to get an understanding of how the model behaves under various configuration parameters provided by the brain. You will also want to make sure your number of iterations stay below 1000, or the brain will struggle to learn. If needed, you can implement custom logic in the **halted()** method in ModelExecuter to help drive behavior. Halted indicates to the brain that the simulator has reached a state that it cannot progress from.
|
|
||||||
|
|
||||||
After you have tested locally, stop your model. Then click **Stop Training** in the Bonsai UI for the brain.
|
|
||||||
|
|
||||||
# Export Your Model
|
|
||||||
|
|
||||||
After you have confirmed your model can connect to the platform locally, it's time to scale your model.
|
|
||||||
|
|
||||||
AnyLogic Professional users can export their model by going to **File** > **Export...** > **to standalone Java application** in the menu bar.
|
|
||||||
|
|
||||||
Select **HeadlessExperiment** in the dialog and the directory where the exported files will reside.
|
|
||||||
|
|
||||||
If you need additional assistance with exporting a model, please see the <a href="https://help.anylogic.com/index.jsp?topic=%2Fcom.anylogic.help%2Fhtml%2Fstandalone%2FExport_Java_Application.html">Exporting a model as a standalone Java application</a> topic in the AnyLogic Help topics.
|
|
||||||
|
|
||||||
If you are not able to export your model to a standalone Java application you may use the example <a href="exported.zip">exported.zip</a> file to use for scaling.
|
|
||||||
|
|
||||||
# Scale Your Model
|
|
||||||
|
|
||||||
Once you have exported your model, you can zip the entire contents of the folder that contains the exported application.
|
|
||||||
|
|
||||||
For example, if your folder structure is:
|
|
||||||
|
|
||||||
```
|
|
||||||
Activity Based Costing Analysis Exported
|
|
||||||
└─── lib
|
|
||||||
| |── AnyLogic Model End User Agreement.pdf
|
|
||||||
| └── ... jar files ...
|
|
||||||
|─── Activity Based Costing Analysis_linux.sh
|
|
||||||
|─── ... jar files ...
|
|
||||||
└─── readme.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
Then you only need to zip the parent **Activity Based Costing Analysis Exported** folder.
|
|
||||||
|
|
||||||
Back in the Bonsai UI, next to **Simulators**, click the **Add sim** button.
|
|
||||||
|
|
||||||
This will open a dialog.
|
|
||||||
|
|
||||||
<img src="images/add_sim.png" alt="Add Sim Prompt" width="500" border="1"/>
|
|
||||||
|
|
||||||
Select AnyLogic.
|
|
||||||
|
|
||||||
<img src="images/add_sim_al_nozip.png" alt="Add Sim Prompt 2" width="500" border="1"/>
|
|
||||||
|
|
||||||
Select or drag the zip file containing the exported model.
|
|
||||||
|
|
||||||
<img src="images/add_sim_al_zip.png" alt="Add Sim Prompt 3" width="500" border="1"/>
|
|
||||||
|
|
||||||
Give your simulator a name, then click **Create simulator**.
|
|
||||||
|
|
||||||
After the simulator is created you will see the new simulator appear under the **Simulators** section.
|
|
||||||
|
|
||||||
Now click the *Teach* tab.
|
|
||||||
|
|
||||||
In the simulator definition, just after the open brackets, add a <a href="#">package</a> statement using the name of the simulator you gave during the Add Simulator dialog above.
|
|
||||||
|
|
||||||
```
|
|
||||||
simulator Simulator(action: Action, config: SimConfig): SimState {
|
|
||||||
package "<simulator_name_from_upload>"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Now click **Train**. Since you indicated the package name you do not need to select a simulator from the dropdown like you did when you started locally.
|
|
||||||
|
|
||||||
In a few minutes time you will see several simulators connect to and train your brain.
|
|
||||||
|
|
||||||
# Sample Results
|
|
||||||
You can read about how the Bonsai brain performed against the default AnyLogic optimizer in the `ABCA-Optimization-Writeup.docx` file.
|
|
||||||
|
|
||||||
# Using Bonsai Assessment with Your Model
|
|
||||||
Starting an Assessment session is similar to starting a training session. Start your AnimatedExperiment and wait for it to register. In the Bonsai UI, using your already-trained brain, click the **Assessment** button. Then select the name of your simulator
|
|
||||||
|
|
|
@ -1,145 +0,0 @@
|
||||||
# Copyright (c) Microsoft Corporation.
|
|
||||||
# Licensed under the MIT License.
|
|
||||||
inkling "2.0"
|
|
||||||
using Number
|
|
||||||
using Math
|
|
||||||
|
|
||||||
#SimState has the same properties as the ModelObservation class in the model
|
|
||||||
type SimState {
|
|
||||||
arrivalRate: number,
|
|
||||||
|
|
||||||
nResA: number,
|
|
||||||
nResB: number,
|
|
||||||
processTime: number,
|
|
||||||
conveyorSpeed: number,
|
|
||||||
|
|
||||||
utilResA: number,
|
|
||||||
utilResB: number,
|
|
||||||
|
|
||||||
ratioFullQueueA: number,
|
|
||||||
ratioFullQueueB: number,
|
|
||||||
|
|
||||||
recentNProducts: number,
|
|
||||||
|
|
||||||
ratioCostIdleA: number,
|
|
||||||
ratioCostIdleB: number,
|
|
||||||
ratioCostWaiting: number,
|
|
||||||
ratioCostProcessing: number,
|
|
||||||
ratioCostMoving: number,
|
|
||||||
|
|
||||||
costPerProduct: number,
|
|
||||||
exceededCapacity: number,
|
|
||||||
time: number
|
|
||||||
}
|
|
||||||
|
|
||||||
#the ObservableState is what the brain sees from the simulator
|
|
||||||
#inthis case, just the arrivalRate
|
|
||||||
type ObservableState {
|
|
||||||
arrivalRate: number
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type Action {
|
|
||||||
nResA: number<1 .. 20>,
|
|
||||||
nResB: number<1 .. 20>,
|
|
||||||
processTime: number<1.0 .. 12.0>,
|
|
||||||
conveyorSpeed: number<0.01 .. 1.0>,
|
|
||||||
}
|
|
||||||
|
|
||||||
type SimConfig {
|
|
||||||
arrivalRate: number,
|
|
||||||
initNResA: number,
|
|
||||||
initNResB: number,
|
|
||||||
initProcessTime: number,
|
|
||||||
initConveyorSpeed: number,
|
|
||||||
sizeBufferQueues: number
|
|
||||||
}
|
|
||||||
|
|
||||||
simulator Simulator(action: Action, config: SimConfig): SimState {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#SimAction is the values translated for the sim
|
|
||||||
#we do not need ranges here
|
|
||||||
#these are the same as the ModelAction class
|
|
||||||
type SimAction {
|
|
||||||
nResA: number,
|
|
||||||
nResB: number,
|
|
||||||
processTime: number,
|
|
||||||
conveyorSpeed: number,
|
|
||||||
}
|
|
||||||
#rounds the value
|
|
||||||
function RoundToNearest(rValue: number, nPlaces: number)
|
|
||||||
{
|
|
||||||
var baseInteger = Math.Floor(rValue)
|
|
||||||
var decimalValue = rValue - baseInteger
|
|
||||||
var tenthsValue = decimalValue * (10 ** nPlaces)
|
|
||||||
var iTenthsPosition = Math.Floor(tenthsValue)
|
|
||||||
var hundrethsPos = tenthsValue - iTenthsPosition
|
|
||||||
var newTenthsValue = 0
|
|
||||||
if (hundrethsPos >= .5)
|
|
||||||
{
|
|
||||||
newTenthsValue = iTenthsPosition + 1
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
newTenthsValue = iTenthsPosition
|
|
||||||
}
|
|
||||||
var finalValue = baseInteger + (newTenthsValue * (10**(-nPlaces)))
|
|
||||||
return finalValue
|
|
||||||
}
|
|
||||||
|
|
||||||
#translates the Action from the brain to the SimAction that is sent to the simulator
|
|
||||||
function TranslateBonsaiActiontoSimAction(a: Action) : SimAction
|
|
||||||
{
|
|
||||||
return
|
|
||||||
{
|
|
||||||
nResA: Math.Floor(a.nResA+0.5),
|
|
||||||
nResB: Math.Floor(a.nResB+0.5),
|
|
||||||
processTime: RoundToNearest(a.processTime, 1),
|
|
||||||
conveyorSpeed: RoundToNearest(a.conveyorSpeed, 2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function Terminal(obs:SimState)
|
|
||||||
{
|
|
||||||
if(obs.exceededCapacity == 1)
|
|
||||||
{
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
#the brain gets one chance at the answer
|
|
||||||
if(obs.time >= 1)
|
|
||||||
{
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
function Reward(obs: SimState) {
|
|
||||||
|
|
||||||
return -obs.costPerProduct - 1000 * obs.exceededCapacity
|
|
||||||
|
|
||||||
}
|
|
||||||
graph (input: ObservableState): Action {
|
|
||||||
|
|
||||||
concept optimize(input): Action {
|
|
||||||
curriculum {
|
|
||||||
source Simulator
|
|
||||||
action TranslateBonsaiActiontoSimAction
|
|
||||||
reward Reward
|
|
||||||
terminal Terminal
|
|
||||||
lesson `Vary Arrival Rate` {
|
|
||||||
#these mape to the SimConfig values
|
|
||||||
scenario {
|
|
||||||
arrivalRate: number<0.5 .. 2.0 step .1>,
|
|
||||||
initNResA: 20,
|
|
||||||
initNResB: 20,
|
|
||||||
initProcessTime: 1.0,
|
|
||||||
initConveyorSpeed: 0.1,
|
|
||||||
sizeBufferQueues: 45
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
output optimize
|
|
||||||
}
|
|
Двоичные данные
deprecated/samples/abca/exported.zip
Двоичные данные
deprecated/samples/abca/images/add_sim.png
До Ширина: | Высота: | Размер: 163 KiB |
Двоичные данные
deprecated/samples/abca/images/add_sim_al_nozip.png
До Ширина: | Высота: | Размер: 81 KiB |
Двоичные данные
deprecated/samples/abca/images/add_sim_al_zip.png
До Ширина: | Высота: | Размер: 66 KiB |
Двоичные данные
deprecated/samples/abca/model/AnyLogic model logo dark.png
До Ширина: | Высота: | Размер: 5.6 KiB |
Двоичные данные
deprecated/samples/abca/model/bonsai-logo.png
До Ширина: | Высота: | Размер: 16 KiB |
|
@ -1,112 +0,0 @@
|
||||||
# Product Delivery Overview
|
|
||||||
This model simulates product delivery in USA. The supply chain includes three manufacturing facilities and fifteen distributors that order random amounts of the product – between 500 and 1000, uniformly distributed – each 1 to 2 days (uniformly distributed). There is a fleet of trucks in each manufacturing facility. When a manufacturing facility receives an order from a distributor, it checks the number of products in storage. If the required amount is available, it sends a loaded truck to the distributor. Otherwise, the order waits until the factory produces the sufficient number of products. Orders are queued in FIFO order.
|
|
||||||
|
|
||||||
### Complexity
|
|
||||||
- The demand coming from each distribution center should be varied:
|
|
||||||
- Seasonal change
|
|
||||||
- Sudden disruptions/surge in demand
|
|
||||||
|
|
||||||
### Observation space
|
|
||||||
- Inventory level at each manufacturing location
|
|
||||||
- Number of trucks, number of idle vs busy trucks, utilization of fleet at each location
|
|
||||||
- Whether manufacturing facility is open or not
|
|
||||||
- Average waiting time for orders placed at each manufacturer
|
|
||||||
- Average waiting time for all manufacturing facilities
|
|
||||||
|
|
||||||
### Action space
|
|
||||||
- Production rate of each facility
|
|
||||||
- Number of trucks in each facility
|
|
||||||
- If a facility should stay open or not
|
|
||||||
|
|
||||||
### Reward
|
|
||||||
- The reward is driven by minimizing the cost of average wait time across the system.
|
|
||||||
|
|
||||||
# Create a Brain
|
|
||||||
|
|
||||||
To start a new brain for this model:
|
|
||||||
|
|
||||||
1. Create an account or sign into Bonsai.
|
|
||||||
2. Click **Create brain** button in the top left, then select **Empty brain** in the dialog.
|
|
||||||
3. Name your new brain (e.g., “product-delivery”).
|
|
||||||
4. Click **Create Brain**. This will create a new brain for you.
|
|
||||||
|
|
||||||
Copy the contents of <a href="product_delivery.ink">product_delivery.ink</a> in to the *Teach* tab for your new brain.
|
|
||||||
|
|
||||||
Do not click Train yet.
|
|
||||||
|
|
||||||
# Running the Model
|
|
||||||
|
|
||||||
To run the model, right click on **AnimatedExperiment** then click the **Run** button. You will see text in the console about registering with the Bonsai platform. Once registration is complete (it will only take a few seconds), go back to the Bonsai dashboard where you created your brain.
|
|
||||||
|
|
||||||
Click the **Train** button. The simulator with the name matching your simulator will appear (in the example above, this is called *AnyLogic - ABCA*). Click the name of your simulator.
|
|
||||||
|
|
||||||
If this is the first start of your brain it may take a few minutes for the brain to generate the appropriate parameters and connect to the simulator. Once the connection is made you will see your first episodeStart event fire in the ModelExecuter handler.
|
|
||||||
|
|
||||||
You may decide to let your training run for a bit, particularly across multiple episode start events, to get an understanding of how the model behaves under various configuration parameters provided by the brain. You will also want to make sure your number of iterations stay below 1000, or the brain will struggle to learn. If needed, you can implement custom logic in the **halted()** method in ModelExecuter to help drive behavior. Halted indicates to the brain that the simulator has reached a state that it cannot progress from.
|
|
||||||
|
|
||||||
After you have tested locally, stop your model. Then click **Stop Training** in the Bonsai dashboard for the brain.
|
|
||||||
|
|
||||||
# Export Your Model
|
|
||||||
|
|
||||||
After you have confirmed your model can connect to the platform locally, it's time to scale your model.
|
|
||||||
|
|
||||||
AnyLogic Professional users can export their model by going to **File** > **Export...** > **to standalone Java application** in the menu bar.
|
|
||||||
|
|
||||||
Select **HeadlessExperiment** in the dialog and the directory where the exported files will reside.
|
|
||||||
|
|
||||||
If you need additional assistance with exporting a model, please see the <a href="https://help.anylogic.com/index.jsp?topic=%2Fcom.anylogic.help%2Fhtml%2Fstandalone%2FExport_Java_Application.html">Exporting a model as a standalone Java application</a> topic in the AnyLogic Help topics.
|
|
||||||
|
|
||||||
If you are not able to export your model to a standalone Java application you may use the example <a href="exported.zip">exported.zip</a> file to use for scaling.
|
|
||||||
|
|
||||||
# Scale Your Model
|
|
||||||
|
|
||||||
Once you have exported your model, you can zip the entire contents of the folder that contains the exported application.
|
|
||||||
|
|
||||||
For example, if your folder structure is:
|
|
||||||
|
|
||||||
```
|
|
||||||
Product Delivery Exported
|
|
||||||
└─── lib
|
|
||||||
| |── AnyLogic Model End User Agreement.pdf
|
|
||||||
| └── ... jar files ...
|
|
||||||
|─── Product Delivery_linux.sh
|
|
||||||
|─── ... jar files ...
|
|
||||||
└─── readme.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
Then you only need to zip the parent **Product Delivery Exported** folder.
|
|
||||||
|
|
||||||
Back in the Bonsai dashboard, next to **Simulators**, click the **Add sim** button.
|
|
||||||
|
|
||||||
This will open a dialog.
|
|
||||||
|
|
||||||
<img src="images/add_sim.png" alt="Add Sim Prompt" width="500" border="1"/>
|
|
||||||
|
|
||||||
Select AnyLogic.
|
|
||||||
|
|
||||||
<img src="images/add_sim_al_nozip.png" alt="Add Sim Prompt 2" width="500" border="1"/>
|
|
||||||
|
|
||||||
Select or drag the zip file containing the exported model.
|
|
||||||
|
|
||||||
<img src="images/add_sim_al_zip.png" alt="Add Sim Prompt 3" width="500" border="1"/>
|
|
||||||
|
|
||||||
Give your simulator a name, then click **Create simulator**.
|
|
||||||
|
|
||||||
After the simulator is created you will see the new simulator appear under the **Simulators** section.
|
|
||||||
|
|
||||||
Now click the *Teach* tab.
|
|
||||||
|
|
||||||
In the simulator definition, just after the open brackets, add a package</a> statement using the name of the simulator you gave during the Add Simulator dialog above.
|
|
||||||
|
|
||||||
```
|
|
||||||
simulator Simulator(action: Action, config: SimConfig): SimState {
|
|
||||||
package "<simulator_name>"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Now click **Train**. Since you indicated the package name you do not need to select a simulator from the dropdown like you did when you started locally.
|
|
||||||
|
|
||||||
In a few minutes time you will see several simulators connect to and train your brain.
|
|
||||||
|
|
||||||
# Using Bonsai Assessment with Your Model
|
|
||||||
Starting an Assessment session is similar to starting a training session. Start your AnimatedExperiment class and wait for it to register. In the Bonsai UI, using your already-trained brain, click the **Assessment** button. Then select the name of your simulator.
|
|
Двоичные данные
deprecated/samples/product-delivery/exported.zip
Двоичные данные
deprecated/samples/product-delivery/images/add_sim.png
До Ширина: | Высота: | Размер: 163 KiB |
Двоичные данные
deprecated/samples/product-delivery/images/add_sim_al_nozip.png
До Ширина: | Высота: | Размер: 81 KiB |
Двоичные данные
deprecated/samples/product-delivery/images/add_sim_al_zip.png
До Ширина: | Высота: | Размер: 66 KiB |
До Ширина: | Высота: | Размер: 5.6 KiB |
Двоичные данные
deprecated/samples/product-delivery/model/bonsai-logo.png
До Ширина: | Высота: | Размер: 16 KiB |
|
@ -1,5 +0,0 @@
|
||||||
#HSQL Database Engine 2.4.1
|
|
||||||
#Mon May 18 23:51:19 UTC 2020
|
|
||||||
tx_timestamp=0
|
|
||||||
modified=no
|
|
||||||
version=2.4.1
|
|
|
@ -1,105 +0,0 @@
|
||||||
SET DATABASE UNIQUE NAME HSQLDB6B2845B5DD
|
|
||||||
SET DATABASE GC 0
|
|
||||||
SET DATABASE DEFAULT RESULT MEMORY ROWS 0
|
|
||||||
SET DATABASE EVENT LOG LEVEL 0
|
|
||||||
SET DATABASE TRANSACTION CONTROL LOCKS
|
|
||||||
SET DATABASE DEFAULT ISOLATION LEVEL READ COMMITTED
|
|
||||||
SET DATABASE TRANSACTION ROLLBACK ON CONFLICT TRUE
|
|
||||||
SET DATABASE TEXT TABLE DEFAULTS ''
|
|
||||||
SET DATABASE SQL NAMES FALSE
|
|
||||||
SET DATABASE SQL REFERENCES FALSE
|
|
||||||
SET DATABASE SQL SIZE TRUE
|
|
||||||
SET DATABASE SQL TYPES FALSE
|
|
||||||
SET DATABASE SQL TDC DELETE TRUE
|
|
||||||
SET DATABASE SQL TDC UPDATE TRUE
|
|
||||||
SET DATABASE SQL CONCAT NULLS TRUE
|
|
||||||
SET DATABASE SQL UNIQUE NULLS TRUE
|
|
||||||
SET DATABASE SQL CONVERT TRUNCATE TRUE
|
|
||||||
SET DATABASE SQL AVG SCALE 0
|
|
||||||
SET DATABASE SQL DOUBLE NAN TRUE
|
|
||||||
SET FILES WRITE DELAY 500 MILLIS
|
|
||||||
SET FILES BACKUP INCREMENT TRUE
|
|
||||||
SET FILES CACHE SIZE 10000
|
|
||||||
SET FILES CACHE ROWS 50000
|
|
||||||
SET FILES SCALE 32
|
|
||||||
SET FILES LOB SCALE 32
|
|
||||||
SET FILES DEFRAG 0
|
|
||||||
SET FILES NIO TRUE
|
|
||||||
SET FILES NIO SIZE 256
|
|
||||||
SET FILES LOG TRUE
|
|
||||||
SET FILES LOG SIZE 50
|
|
||||||
CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e'
|
|
||||||
ALTER USER SA SET LOCAL TRUE
|
|
||||||
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
|
|
||||||
SET SCHEMA PUBLIC
|
|
||||||
CREATE MEMORY TABLE PUBLIC.AL_CONFIGURATION(PROPERTY_NAME VARCHAR(255) NOT NULL,PROPERTY_VALUE VARCHAR(16777216),UNIQUE(PROPERTY_NAME))
|
|
||||||
CREATE MEMORY TABLE PUBLIC.AL_GROUPS(GROUP_NAME VARCHAR(255) NOT NULL PRIMARY KEY,DESCRIPTION VARCHAR(16777216))
|
|
||||||
CREATE MEMORY TABLE PUBLIC.AL_TABLES(TABLE_NAME VARCHAR(255) NOT NULL PRIMARY KEY,GROUP_NAME VARCHAR(255),DESCRIPTION VARCHAR(16777216))
|
|
||||||
CREATE MEMORY TABLE PUBLIC.AL_CUSTOM_TYPE(TABLE_NAME VARCHAR(255),COLUMN_NAME VARCHAR(255),TYPE VARCHAR(255),NAME VARCHAR(255))
|
|
||||||
CREATE MEMORY TABLE PUBLIC.AL_VIEWS(VIEW_NAME VARCHAR(255) NOT NULL,VIEW_DEFINITION VARCHAR(16777216),IS_VALID BOOLEAN,UNIQUE(VIEW_NAME))
|
|
||||||
CREATE MEMORY TABLE PUBLIC.AL_SELECTED_LOG_OBJECTS(NAME VARCHAR(255) NOT NULL,TYPE VARCHAR(255),UNIQUE(NAME))
|
|
||||||
CREATE MEMORY TABLE PUBLIC.AL_DB_OBJECTS(NAME VARCHAR(255) NOT NULL,TYPE VARCHAR(255),USAGE VARCHAR(255),UNIQUE(NAME))
|
|
||||||
CREATE MEMORY TABLE PUBLIC.DISTRIBUTORS(AL_ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY,CITY VARCHAR(16777216))
|
|
||||||
ALTER TABLE PUBLIC.DISTRIBUTORS ALTER COLUMN AL_ID RESTART WITH 15
|
|
||||||
CREATE MEMORY TABLE PUBLIC.MANUFACTURING_CENTERS(AL_ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY,CITY VARCHAR(16777216))
|
|
||||||
ALTER TABLE PUBLIC.MANUFACTURING_CENTERS ALTER COLUMN AL_ID RESTART WITH 3
|
|
||||||
ALTER SEQUENCE SYSTEM_LOBS.LOB_ID RESTART WITH 1
|
|
||||||
SET DATABASE DEFAULT INITIAL SCHEMA PUBLIC
|
|
||||||
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.SQL_IDENTIFIER TO PUBLIC
|
|
||||||
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.YES_OR_NO TO PUBLIC
|
|
||||||
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC
|
|
||||||
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CARDINAL_NUMBER TO PUBLIC
|
|
||||||
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CHARACTER_DATA TO PUBLIC
|
|
||||||
GRANT DBA TO SA
|
|
||||||
SET SCHEMA SYSTEM_LOBS
|
|
||||||
INSERT INTO BLOCKS VALUES(0,2147483647,0)
|
|
||||||
SET SCHEMA PUBLIC
|
|
||||||
INSERT INTO AL_CONFIGURATION VALUES('VERSION','7.2.0')
|
|
||||||
INSERT INTO AL_TABLES VALUES('distributors',NULL,'')
|
|
||||||
INSERT INTO AL_TABLES VALUES('manufacturing_centers',NULL,'')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('agents_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('library_blocks_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('agent_parameters_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('library_block_parameters_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('agent_movement_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('agent_movement_stats_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('agent_messages_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('events_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('flowchart_entries_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('flowchart_process_states_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('flowchart_stats_time_in_state_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('resource_unit_states_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('resource_unit_task_stats_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('resource_pool_task_stats_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('resource_pool_utilization_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('resource_unit_utilization_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('fluid_units_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('fluid_storages_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('fluid_rates_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('fluid_utilization_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('statechart_transitions_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('agent_statechart_states_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('agent_statechart_stats_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('agent_type_statechart_stats_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('statistics_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('datasets_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('histograms_log','VIEW')
|
|
||||||
INSERT INTO AL_SELECTED_LOG_OBJECTS VALUES('trace_log','VIEW')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(0,'Madison')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(1,'Cedar Rapids')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(2,'Memphis')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(3,'St.Louis')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(4,'Peoria')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(5,'Dayton')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(6,'Evansville')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(7,'Topeka')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(8,'Knoxville')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(9,'Richmond')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(10,'Charleston')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(11,'Harrisburg')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(12,'Norfolk')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(13,'Linkoln')
|
|
||||||
INSERT INTO DISTRIBUTORS VALUES(14,'Tulsa')
|
|
||||||
INSERT INTO MANUFACTURING_CENTERS VALUES(0,'Chicago')
|
|
||||||
INSERT INTO MANUFACTURING_CENTERS VALUES(1,'Pittsburg')
|
|
||||||
INSERT INTO MANUFACTURING_CENTERS VALUES(2,'Nashville')
|
|
Двоичные данные
deprecated/samples/product-delivery/model/sim_layout.jpg
До Ширина: | Высота: | Размер: 193 KiB |
|
@ -1,188 +0,0 @@
|
||||||
# Copyright (c) Microsoft Corporation.
|
|
||||||
# Licensed under the MIT License.
|
|
||||||
|
|
||||||
inkling "2.0"
|
|
||||||
|
|
||||||
using Number
|
|
||||||
using Math
|
|
||||||
|
|
||||||
#what the simulator sends
|
|
||||||
type SimState {
|
|
||||||
Chicago_is_open: Number.Int8<0..1>,
|
|
||||||
Pittsburg_is_open: Number.Int8<0..1>,
|
|
||||||
Nashville_is_open: Number.Int8<0..1>,
|
|
||||||
|
|
||||||
Chicago_util_trucks: number<0..1>,
|
|
||||||
Pittsburg_util_trucks: number<0..1>,
|
|
||||||
Nashville_util_trucks: number<0..1>,
|
|
||||||
|
|
||||||
Chicago_inventory_level: number<0..30000>,
|
|
||||||
Pittsburg_inventory_level: number<0..30000>,
|
|
||||||
Nashville_inventory_level: number<0..30000>,
|
|
||||||
|
|
||||||
Chicago_orders_queueing: number<0 .. 100>,
|
|
||||||
Pittsburg_orders_queueing: number<0 .. 100>,
|
|
||||||
Nashville_orders_queueing: number<0 .. 100>,
|
|
||||||
|
|
||||||
Chicago_production_rate: number<50 .. 80>,
|
|
||||||
Pittsburg_production_rate: number<50 .. 80>,
|
|
||||||
Nashville_production_rate: number<50 .. 80>,
|
|
||||||
|
|
||||||
# technically, all of the following can be 'infinity' if no products completed yet
|
|
||||||
# we set them to -1, as an indicator. otherwise 0 is the minimum value
|
|
||||||
Chicago_average_turnaround: number<-1 .. 500>,
|
|
||||||
Pittsburg_average_turnaround: number<-1 .. 500>,
|
|
||||||
Nashville_average_turnaround: number<-1 .. 500>,
|
|
||||||
|
|
||||||
Chicago_cost_per_product: number<-1 .. 4000000>,
|
|
||||||
Pittsburg_cost_per_product: number<-1 .. 4000000>,
|
|
||||||
Nashville_cost_per_product: number<-1 .. 4000000>,
|
|
||||||
|
|
||||||
overall_average_turnaround: number<-1 .. 500>,
|
|
||||||
overall_average_cost_per_product: number<-1 .. 4000000>,
|
|
||||||
|
|
||||||
#based on model time
|
|
||||||
time: number<0 .. 800>
|
|
||||||
}
|
|
||||||
|
|
||||||
#what the brain sees during training
|
|
||||||
type ObservationState {
|
|
||||||
Chicago_is_open: Number.Int8<0..1>,
|
|
||||||
Pittsburg_is_open: Number.Int8<0..1>,
|
|
||||||
Nashville_is_open: Number.Int8<0..1>,
|
|
||||||
|
|
||||||
Chicago_util_trucks: number<0..1>,
|
|
||||||
Pittsburg_util_trucks: number<0..1>,
|
|
||||||
Nashville_util_trucks: number<0..1>,
|
|
||||||
|
|
||||||
Chicago_inventory_level: number<0..30000>,
|
|
||||||
Pittsburg_inventory_level: number<0..30000>,
|
|
||||||
Nashville_inventory_level: number<0..30000>,
|
|
||||||
|
|
||||||
Chicago_orders_queueing: number<0 .. 100>,
|
|
||||||
Pittsburg_orders_queueing: number<0 .. 100>,
|
|
||||||
Nashville_orders_queueing: number<0 .. 100>,
|
|
||||||
|
|
||||||
Chicago_production_rate: number<50 .. 80>,
|
|
||||||
Pittsburg_production_rate: number<50 .. 80>,
|
|
||||||
Nashville_production_rate: number<50 .. 80>,
|
|
||||||
|
|
||||||
# technically, all of the following can be 'infinity' if no products completed yet
|
|
||||||
# we set them to -1, as an indicator. otherwise 0 is the minimum value
|
|
||||||
Chicago_average_turnaround: number<-1 .. 500>,
|
|
||||||
Pittsburg_average_turnaround: number<-1 .. 500>,
|
|
||||||
Nashville_average_turnaround: number<-1 .. 500>,
|
|
||||||
|
|
||||||
Chicago_cost_per_product: number<-1 .. 4000000>,
|
|
||||||
Pittsburg_cost_per_product: number<-1 .. 4000000>,
|
|
||||||
Nashville_cost_per_product: number<-1 .. 4000000>,
|
|
||||||
|
|
||||||
overall_average_turnaround: number<-1 .. 500>,
|
|
||||||
overall_average_cost_per_product: number<-1 .. 4000000>,
|
|
||||||
}
|
|
||||||
|
|
||||||
type Action {
|
|
||||||
Chicago_is_open: number<0..1>,
|
|
||||||
Pittsburg_is_open: number<0..1>,
|
|
||||||
Nashville_is_open: number<0..1>,
|
|
||||||
|
|
||||||
Chicago_num_trucks: number<1..3>,
|
|
||||||
Pittsburg_num_trucks: number<1..3>,
|
|
||||||
Nashville_num_trucks: number<1..3>,
|
|
||||||
|
|
||||||
Chicago_production_rate: number<50..80>,
|
|
||||||
Pittsburg_production_rate: number<50..80>,
|
|
||||||
Nashville_production_rate: number<50..80>,
|
|
||||||
}
|
|
||||||
|
|
||||||
type AnyLogicAction {
|
|
||||||
Chicago_is_open: number,
|
|
||||||
Pittsburg_is_open: number,
|
|
||||||
Nashville_is_open: number,
|
|
||||||
|
|
||||||
Chicago_num_trucks: number,
|
|
||||||
Pittsburg_num_trucks: number,
|
|
||||||
Nashville_num_trucks: number,
|
|
||||||
|
|
||||||
Chicago_production_rate: number,
|
|
||||||
Pittsburg_production_rate: number,
|
|
||||||
Nashville_production_rate: number
|
|
||||||
}
|
|
||||||
|
|
||||||
type Config {
|
|
||||||
Chicago_is_open: Number.Int8,
|
|
||||||
Pittsburg_is_open: Number.Int8,
|
|
||||||
Nashville_is_open: Number.Int8,
|
|
||||||
}
|
|
||||||
|
|
||||||
function Reward(obs: SimState) {
|
|
||||||
|
|
||||||
# return a harsh penalty if all sites are closed
|
|
||||||
if ( obs.Chicago_is_open + obs.Pittsburg_is_open + obs.Nashville_is_open == 0 )
|
|
||||||
{
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
# scale approx range of turnaround times [2 days, 2 weeks] / [48 hours, 336 hours] to [1, -1]
|
|
||||||
var turnaround_points = ((obs.overall_average_turnaround - 48) / (336 - 48)) * (-1 - 1) + 1
|
|
||||||
|
|
||||||
# scale approx range of cpp [200k, 3.8 mil] to [1, -1]
|
|
||||||
# but first scale down cpp to an easier to write value
|
|
||||||
var cpp = obs.overall_average_cost_per_product / 100000
|
|
||||||
# now scale from [2, 38] to [1, -1]
|
|
||||||
var cpp_points = ((cpp - 2) / (38 - 2)) * (-1 - 1) + 1
|
|
||||||
|
|
||||||
# weight both points equally
|
|
||||||
return (turnaround_points + cpp_points) / 2
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function Terminal(obs: SimState)
|
|
||||||
{
|
|
||||||
return obs.time >= 720
|
|
||||||
}
|
|
||||||
|
|
||||||
function TranslateBonsaiActiontoAnyLogicAction(a: Action) : AnyLogicAction
|
|
||||||
{
|
|
||||||
return
|
|
||||||
{
|
|
||||||
Chicago_is_open: Math.Floor(a.Chicago_is_open+.5),
|
|
||||||
Pittsburg_is_open: Math.Floor(a.Pittsburg_is_open+.5),
|
|
||||||
Nashville_is_open: Math.Floor(a.Nashville_is_open+.5),
|
|
||||||
|
|
||||||
Chicago_num_trucks: Math.Floor(a.Chicago_num_trucks+.5),
|
|
||||||
Pittsburg_num_trucks: Math.Floor(a.Pittsburg_num_trucks+.5),
|
|
||||||
Nashville_num_trucks: Math.Floor(a.Nashville_num_trucks+.5),
|
|
||||||
|
|
||||||
Chicago_production_rate: Math.Floor(a.Chicago_production_rate+.5),
|
|
||||||
Pittsburg_production_rate: Math.Floor(a.Pittsburg_production_rate+.5),
|
|
||||||
Nashville_production_rate: Math.Floor(a.Nashville_production_rate+.5),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
simulator Simulator(action: Action, config: Config): SimState {
|
|
||||||
#package "<simulator_name>"
|
|
||||||
}
|
|
||||||
|
|
||||||
graph (input: ObservationState): Action {
|
|
||||||
|
|
||||||
concept optimize(input): Action {
|
|
||||||
curriculum {
|
|
||||||
source Simulator
|
|
||||||
reward Reward
|
|
||||||
terminal Terminal
|
|
||||||
action TranslateBonsaiActiontoAnyLogicAction
|
|
||||||
|
|
||||||
|
|
||||||
lesson vary {
|
|
||||||
scenario {
|
|
||||||
Chicago_is_open: Number.Int8<0,1,>,
|
|
||||||
Pittsburg_is_open: Number.Int8<0,1,>,
|
|
||||||
Nashville_is_open: Number.Int8<0,1,>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
output optimize
|
|
||||||
}
|
|