Formulating and running a model: house construction scheduling
A tutorial showing you how to use the Modeling Assistant to define formulate and run a model for a house construction scheduling problem. The completed model with data is also provided in the DO-samples.
You need to plan and schedule activities and subcontractors for a house construction project. Your schedule must start on a particular date. All the activities (masonry, carpentry, plumbing and so on) must be scheduled and there is a specified order of activities that must be respected (for example windows cannot be put in until the roof is completed). Each subcontractor can perform some of the necessary activities and with differing level of skills. Your schedule must determine the best (earliest) end time for the construction project ensuring that all activities have been scheduled and decide which subcontractor to assign to each activity. In addition, you would like to know how to optimize the skill level of your subcontractors on this project.
You have data for this project as shown in the following spreadsheet. For each activity you have the duration that is needed to complete it, the activities that must precede it and the possible subcontractors who are available and qualified to perform that activity.
For illustration purposes, there are just 10 activities and 3 subcontractors shown. With Decision Optimization it is easy to change your data and solve the same problem with larger data sets.
For each activity you also have data concerning the level of expertise that each subcontractor has for that activity. The higher the number, the more expertise the subcontractor has. If a subcontractor has a zero skill level, he must not be assigned to the task. The following table shows part of this spreadsheet.
You also have a table containing the names of the Subcontractors (Joe, Jack and so on) available for this project.
Create a Scenario
- Create a New Project for Decision Optimization.
- In your project, click Add model in the Create new menu. (An alternative way to add a model to your project is to click Models and then Add model on your Project page).
- In the Create Model window that opens, enter a name, select Decision Optimization as the type of model and click Create.
- A Scenario 1 is created along with the model, and you work in Scenario 1.
Your Scenario specifies the combination of data and optimization model formulation that you want to solve. You can create different scenarios with different variants of data and model formulations.
Obtain data files for this example
The data files used in this example are available in the DO-samples project, which is pre-installed in Watson Studio. Normally, you would have your files already stored in Watson Studio in your own data asset or locally on your machine, For illustration purposes however, so that you can build the model yourself, in this example you will first download the data files onto your machine and then import them into the project that you have just created. The completed model formulation with imported data is also provided as a sample, see HouseConstructionScheduling in DO-samples.
- In the navigation pane, select Projects>View all Projects, then click DO-samples.
- On the DO-samples project page, click Models in the Assets tab.
- Locate and open the
- Select the Prepare tab to open the Prepare Input Data
view. The files
Subcontractor.csvare displayed as tables.
- Download each file by clicking the Open Menu icon and clicking Download.
Select data to add and import into the Scenario
To add the data files to your Scenario:
- Navigate back to your own project, click Assets, locate the Models section and reopen your model.
- In the Select data view, click add data set.
- Browse to locate the
Subcontractor.csvfiles that you have saved locally, select them and click Open add them to your Scenario.
- Select the three files and click Import to specify the data you want to use for your schedule.
For Decision Optimization models, you can import data files directly like this from within the Model Builder without having to first add them to your data assets. If you already had data sets in this project in Watson Studio, these files would be automatically listed for you to select and import into your Scenario.
Prepare input data
The data files you imported are now displayed as tables in the Prepare Input Data
view. The following image shows the data files
Subcontractor.csv imported in a Scenario.
You can view all the data by clicking the expand arrow in the upper left of the table. You can also view all the data by clicking the Open the table in full mode icon in the upper right of the data table. You can edit values in this scenario directly in this view in full mode or in the expanded tables.
Choose the Modeling Assistant
- Click Run Model in the sidebar and a pop-up window appears asking you how you want to formulate your model (whether you want to create or import a model with Python or OPL, or use the Modeling Assistant).
- Select Use the Modeling Assistant and click Ok.
Define your decision domain
In the Model view: select the decision domain for your problem. In this case select Scheduling. This option is currently only available for Scheduling, Resource Assignment, Selection and Allocation and Supply and Demand domain.
- After selecting your domain, a pop-up window appears for you to map your data to the scheduling concepts Tasks and Resources. Tasks are whatever you want to plan and schedule over time. You must define at least one task to be scheduled. In this example, your tasks are construction activities such as masonry. Resources can be human, machine, equipment or anything you want to use for the tasks. In this case your resources are your subcontractors.
- Under TASKS, click Choose a task and choose
Activityfrom the drop-down list. Then under RESOURCES click Choose a resource and choose
Subcontractor. The names of possible tasks and resources for you to choose from are taken from your imported data. For this example, you only need to map activities and subcontractors, but you could add other tasks and resource mappings if your model required it. You can remove any mapping by hovering over it and selecting the delete icon to its right.
- Click Continue.
How tasks will use resources
In the window, for each task to be scheduled, you have three options :
- Use resources and assign: You can select all the options and choose to have your activities assigned to specific subcontractors. This means that you want to obtain a schedule for your house construction activities with the best sequence of house construction activities, taking into account the start times, durations and precedence order, and so on, but with named subcontractors assigned to the activities. This option is selected by default.
- Use resources without assignment: You can use resources, and clear the While
assigning... check box to choose not to assign specific contractors to your activities. This
means that you want to obtain a schedule for your house construction activities with the best
sequence of house construction activities, taking into account the start times, durations and
precedence order, and so on. You still want the numbers and types of subcontractors you have
available to be considered in the obtained schedule (for example 3 plumbers, 2 carpenters,... ), but
they don't have to be assigned to specific people (for example Joe, Jack, Jim).
When you use resources, with or without assignment, you can also decide to add further time-based capacity constraints to your model. For example you can specify limits on the number of subcontractors that can be used in parallel at any given time, or individual or total subcontractor availability over a time period.
For an example of scheduling without assignment, see BridgeScheduling in DO-samples.
- Continue without resources You can clear all the options and just click Continue to schedule the tasks ignoring all resource limits. This means that you want to obtain a schedule with the best sequence of house construction activities, taking into account the start times, durations, precedence orders, and so on, but without considering your subcontractors.
For this example:
- Choose the default setting with all options (Use the resources...
While assigning...) selected and click Continue.
The problem that you want to solve is now formulated in a concise statement.
- Click Finish.
You return to the Model view. You can edit your problem definition again at any time, by clicking the pencil icon and redefining your mappings and scheduling options.
Your model formulation (left pane)
Now that you have specified the problem that you want to solve, the Modeling Assistant provides you with a partially completed formulation in the Model view. This left pane contains the model that you will run. The right pane contains more suggestions that you can add to your model formulation. If you have re-sized your window, it is possible that the right pane appears in the lower part of your screen.
The model consists of an objective to be attained (maximized or minimized) and some constraints that must be satisfied. For scheduling problems like this, your objective is to work out the best schedule. The best in this case, is one in which the time to complete all the activities is minimized. (You want to complete the house construction as quickly as possible as this will reduce costs.) This objective as well as some standard scheduling constraints have been automatically added to your model. You can also use the search field above the Objectives to search the objectives and constraints.
- each activity has one subcontractor assigned to it
- the duration time for each activity is respected
- all activities are present in the schedule, in other words, no activity can be omitted from the schedule
- the scheduling will be performed from the start time that you define for your construction project
- each subcontractor can only be assigned to one task at a time.
It is possible that your constraints are displayed in a different order.
Some constraints have more details that can be displayed or hidden by clicking the red arrows on each line. A red bar next to the constraint indicates that there is a value or definition that you must add. You can add items by clicking the term shown in red and typing in or selecting from a drop-down list, and you must complete the model before running it, but before doing this, first save a copy by duplicating the scenario as explained later in this section.
In the Model view of your scenario, if you click Reinitialize, you will return to the screen where you choose whether you want to formulate your model with the Modeling Assistant or in a Python notebook or import an existing model. If you choose to reinitialize your model at this stage, you will overwrite your current model and lose your changes. If you want to keep a copy of your current work in progress, create a new scenario before changing the model.
Duplicate the scenario
To keep a copy of this model, make a copy of this scenario:
- If the scenario panel is not open, click the Scenarios icon in the upper right corner of the window.
- Click the three dots next to Scenario 1 and select Duplicate.
- Enter a name for the new scenario, Scenario 2, for example, and click Create. You continue working in Scenario 2.
Complete your model
- If necessary, expand the duration constraint by clicking the red arrow on this line to display
the full definition. Select to be defined shown in red and choose the column name
Duration in days. The default duration unit expressed in default duration unit is added to the end of the constraint. You might modify this by clicking default duration unit and selecting days, but the default unit is days. You can also modify the default duration unit and customize how dates and times are defined, in the Settings panel on the right. Once you have completed the duration constraint, the row is no longer highlighted in red.
- In the Schedule start constraint, click a date and time and enter and select a date from the drop-down menu. You could also enter a date and time. If you enter a date without a time, the default time is taken to be 00:00. Once you have specified at least a date, the row is no longer highlighted in red.
The red bars disappear once you have entered values. The model, however, isn't quite complete. You might want to make sure that your schedule takes into account the order of precedence of tasks so that each activity can only start after those that must precede it. You will add this constraint later.
If your model had more objectives and constraints, you could browse or filter them by using the Find in my objectives and constraints search field.
You can choose to Disable or Remove any one of the objectives or constraints in your model by clicking the 3 vertical dots next to the statement. This menu also enables you to reorganize the order of your statements by moving them up and down and you can also duplicate a statement.
When you have completed your model, or when there are no objectives or constraints still highlighted in red, you can run it to find a solution that will decide the best optimal schedule based on your model objectives and constraints.
Run your model
You can change the solve time limit for your model in the Model view in the Settings tab on the right. For this example, use the default limit. Other parameters can also be set using run configuration parameters (see Run parameters and Decision Optimization environment for more information).
In Scenario 2, click the Run button in the upper right of the Model view to run the model. A pop-up window appears to show you the progress of this run and while this is showing, you cannot edit the model. When an initial objective value has been found, a Combined Objective is displayed in this run status pop-up window. If you want to end this run before the optimal solution is obtained, you can quit by clicking Stop the run. When the optimal solution has been found the pop-up window closes.
When the run is completed, you can see the results in the Solution view. You can also click LOG to inspect the solver engine log files. The first table in the Solution view shows the objective (or objectives if you have several) with its values and the subsequent tables provide you with the best schedule with the assignment of activities to subcontractors.
You can also download the solution tables as
In the Dashboard view, click Gantt to display the solution as a Gantt chart.
Create a new scenario - different model, same data
Although you have solved the model and now have the optimal schedule for your activities with subcontractors assigned, you haven't as yet considered the precedence of activities nor the skill level data of your subcontractors in making the assignments. Scenarios enable you to analyze and compare different models and data.
First, examine a new scenario with an additional constraint:
In the Model view, other objectives and constraints are offered in the Suggestions pane on the right side of the window. You can add these to your model by clicking them. To see other suggestions that are not listed on the right, start typing in the search field and press enter or the refresh button. You can then browse and add from the displayed propositions.
To add the precedence constraint to your model to ensure that there are no time lags between activities:
- Duplicate Scenario 2 and call it Scenario 3.
- In the Suggestions pane in the Model view, type in natural language activity after preceding activities for example, in the search field and click the refresh icon.
- From the new list of suggestions in the right pane, click Each Activity starts after the end
of preceding activities to add it to your constraints.
The new precedence constraint appears in your model formulation.
- Rerun the model (scenario 3) and look at the new solution. You can compare this to the solution you obtained in scenario 2 when you solved the model without this constraint.
Next, examine a new scenario with an additional objective and more constraints:
- Duplicate Scenario 3 and call it Scenario 4
To maximize the subcontractors' skill levels in their assignment to activities:
- In the Model view, type overall
quality in the suggestions search field to find and add the following objective to your
Maximize overall quality of Subcontractor to Activity assignments according to table of assignment values.
Click the red <table of assignment value> and type or select Expertise.
Your new objective is now Maximize overall quality of scheduling assignments according to Expertise. Expand the objective and select Subcontractor for the resource, Activity for the task, and Skill level for the value, to complete the definition.
You now have two objectives. You can decide whether the objectives are to be considered equally or with different weightings. You can increase and decrease the weights on each objective by using the slider to its right. Leave the two sliders at 5 so that your two objectives are equally weighted. You can also add scale factors for the objectives. For this example, leave the scale factors as 1. For more information see Weights and scale factors displayed in the solution.
- To ensure that subcontractors only undertake tasks that they are permitted to do, add a new constraint. Type in the suggestions, for example, subcontractor must be in possible subcontractors. Click Use topics to filter the suggestions. and select the filter Assignment>Compatibility. Click the Apply button.
- From the filtered suggestions, find and add the following constraint:
For each Subcontractor to Activity assignment, Subcontractor must be in Possible Subcontractors for Activity.
- Run the model
The new solution now shows a new assignment of subcontractors.
More about the Model view (right pane)
The Suggestions filter
You can also filter the suggestions to find objectives and constraints. Click Use topics to filter the suggestions which opens a pane for you to select various topics of interest and apply filters to the list of suggestions. Scheduling settings are constraints that are time related, for example, that all activities must start after a particular start date. Once you have selected items in a topic and the filter is applied, a box is displayed showing you your chosen topic name and the number of subtopics that you have selected. To reopen the pane click any one of these filter boxes. To remove filters, click the remove icon on each filter.
For example, type "carpentry after masonry" in the Suggestions search field. A list of related constraints and objectives are provided. Now use the topics and select Precedence as an option under the Tasks topic and click Apply. The result is filtered to show fewer suggestions.
The Settings tab
The Settings tab in the Model view lists different scheduling and optimization parameters that can be edited. In this example the default duration unit, the optimization run time and the date/time format are shown. You can specify here a customized date/time format to suit your data.
The Data Schema tab
The Data Schema tab view lists, table by table, all information that the Modeling Assistant has imported and deduced from the input data that is necessary for the scheduling problem to be solved. This can be useful for expert users for data debugging purposes.
Generating a Python notebook from your scenario
- If the scenario panel is not open, click the Scenarios icon in the upper right corner of the window.
- Click the three dots next to Scenario 1 and select Generate a Python notebook from this scenario.
- Enter a name for your notebook and click Generate.
In the Dashboard you can customize what you want to see displayed from any
scenario. You can view your input data, your solution and add notes. You can use table widgets and
chart widgets to customize the layout of these views. You can add headers, change background colors
and other properties of your notes, tables or charts. You can choose different types of charts such
as line charts, bar charts, and so on. You can define how data is aggregated in these charts and use
calculate property to define how to represent certain data values in your
If you select a table or chart widget, a default instance is displayed using some of your input
data. To change the content and format of this object, click the pencil icon and edit the widget
with either the graphical editor or by editing the
You can use the dashboard to visually compare scenarios.
For more information on Dashboard components, see Dashboard.