Step 1: Develop a Data Model

1. Meet the Default Data Model

Let’s take a look at the com.company.warehouse.datamodel bundle.

It already contains a basic data model with Scenario, Arc, Node, and Point classes (see the model/datamodel.ecore file):

datamodel

These are the classes to describe the main object (scenario) and the transport network. The Scenario is the root class. A (singleton) Scenario object 'contains' all other objects. Node, Arc, and Point are the data model classes whose instances form a transportation graph.

2. An Empty Scenario

The newly created application already supports editing the basic scenario properties:

Editing scenario properties

You can also create the transport network using the Map part:

Editing transport network

3. Enhance the Data Model

For this tutorial, we will also need other entities, so let’s add them to our data model.

3.1. Create a new Forklift EClass

  1. In the datamodel.ecore file editor, right-click on the datamodel item and select the New Child → EClass menu item. A new data model class is created.

  2. In its properties, set its Name to Forklift.

  3. Add the following fields to the Forklift EClass using its New Child context menu item:

Field type Name EType

EReference

scenario

Scenario

EAttribute

name

EString

EReference

base

Node

EAttribute

velocity

EDouble

EAttribute

loadingTimeSec

EDouble

EAttribute

unloadingTimeSec

EDouble

3.2. Create a new Direction EEnum

  1. In the datamodel.ecore file editor, right-click on the datamodel item and select the New Child → EEnum menu item. A new data model enumeration is created.

  2. In its properties, set its Name to Direction.

  3. Right-click the Direction enum and in its context menu choose New Child → EEnum Literal. Set the literal’s Literal and Name properties to 'IN', and Value property to 0 (zero).

  4. In the same manner, add another literal to Direction, with Literal and Name equal to 'OUT' and Value equal to 1.

  5. Set Direction enum Default Value property to 'IN (0)'.

If you’ve already got the idea of how we can define data model types and their properties in Eclipse Model Editor, and if you’ve had enough of filling all those fields, you can just:

  1. Download a complete datamodel.ecore file. (Alt+Click the link)

  2. Replace datamodel.ecore file in your project with the downloaded one.

  3. Proceed to the next Generate Data Model Java Classes section.

3.3. Create a new Gate EClass

  1. Create a new data model EClass with name= Gate

  2. Add new fields to EClass Gate:

Field type Name EType ID Upper Bound

EReference

scenario

Scenario

EAttribute

id

EString

true

EAttribute

direction

Direction

EReference

entrance

Node

EReference

places

Node

-1

3.4. Add new fields to the Scenario EClass:

Field type Name EType Containment EOpposite Upper Bound

EAttribute

truckCapacity

EInt

EAttribute

truckArrivalIntervalMin

EDouble

EReference

forklifts

Forklift

true

scenario

-1

EReference

storagePlaces

Node

-1

EReference

gates

Gate

true

scenario

-1

3.5. Save the modified datamodel.ecore file.

Check if you have the data model similar to this one:

datamodel

4. Generate Data Model Java Classes

With EMF, it is easy to map datamodel classes (described in the datamodel.ecore file) to Java classes.

In the datamodel.genmodel file (located next to the datamodel.ecore file) editor, right-click the child Datamodel element and choose Generate Model Code.

It might take a few seconds to generate the Java classes.

You can find the generated files in the src-gen folder of the datamodel bundle.

Each time you change the datamodel.ecore file, these Java classes should be regenerated to reflect the changes.

5. Download & open template scenario

Here you can find the scenario that matches the up-to-date data model and contains some data: Warehouse_Scenario.xlsx

Download this excel file to your project’s root directory.

Open it from the application with File / Open menu.

If you get an error during opening the file, the most likely reason is that you made a mistake filling datamodel.ecore.

Don’t despair, you can just download the ready-made correct file (datamodel.ecore). (Alt+Click the link)

Remember to regenerate model Java classes when you change datamodel.ecore file.

If everything goes right, you should see the following picture in the Map pane:

warehouse map

6. Exploring the scenario

You may open Warehouse_Scenario.xlsx in Excel and look through its sheets to get to know how scenario data is organized. Here is the data for all the objects and relations that we specified in the datamodel.ecore.

Let’s see what we have on the warehouse plan:

warehouse map explained

7. Run the empty model simulation

Switch to simulation mode: Mode / Simulation

Press the Run button in the toolbar. See the time indication is running and… Nothing happens!

That’s right. We created only a static data model and haven’t added any events to our simulation yet.