×
Community Blog Solving Task Assignment Problems (Getting Started with Mindopt)

Solving Task Assignment Problems (Getting Started with Mindopt)

This article discusses MindOpt APL (MAPL) and how MindOpt Solver supports solving linear programming (LP) problems.

1. Dual-Task Assignment Problem

Problem Description

Each day, an employee is responsible for task a (parts manufacturing) and task b (parts assembly). The reward for participating in task a is 100 yuan/hour, and the reward for task b is 150 yuan/hour. The factory requires the employee to spend at least three hours per day on each task. Given that the employee works eight hours a day (therefore can make their own decision for the last two hours), how can they divide time between the two tasks for the most compensation?

These problems are a simple task allocation problem and a miniature production scheduling problem.

Optimization Model

An optimization problem consists of three elements: decision variables, constraints, and an objective. Since the employee is making decisions about time allocation, we introduce decision variables xa and xb to represent how long they will spend on task a and task b. From the problem description, these variables need to satisfy xa + xb = 8, xa ≥ 3, and xb ≥ 3. In addition, the worker's goal is to maximize 100xa + 150xb. With the three elements defined, we arrive at the following model:



Variables: xa,xb
Objective: maximize 100xa + 150xb
Constraints: subject to xa + xb = 8
xa ≥3, xb ≥3

2. MAPL Code

MindOpt APL (MAPL) is an algebraic modeling language, which can easily describe mathematical language as a program and then call various solvers to solve it. MindOpt Solver supports solving linear programming (LP) problems. Rewrite the data graph and mathematical model above, as shown in the following code:

var xa >= 3;   # declare variable xa 
var xb >= 3;   # declare variable xb
maximize Reward: 100 * xa + 150 * xb;  # declare maximization objective
subto Worker_time: xa + xb == 8;       # declare constraint

Then, we run and debug the code in this notebook.

2.1. Method 1: Enter Code Directly in the Cell

Enter the following modeling and solving code directly in the cell:

clear model;  #Used when running multiple times to clear the model
option modelname model/twoTask; #Facilitate the generation of intermediate files in the same directory as Method 2.

print "-----------------Model and Solve---------------";

#--------------------------
# twoTask.mapl
var xa >= 3;   # declare variable xa 
var xb >= 3;   # declare variable xb
maximize Reward: 100 * xa + 150 * xb;  # declare maximization objective
subto Worker_time: xa + xb == 8;       # declare constraint
#--------------------------


option solver mindopt;     # (optional) solver selection, default: MindOpt
solve;         # solve

print "-----------------Display---------------";
display;        # display results
print "Objective = ";
print 100 * xa + 150 * xb;

2.1. Method 2: Save the Codes in the .mapl File

We can save the modeling codes in file twoTask.mapl and call MAPL to load the file and solve it.

Here, we can also try another solver to solve the problem:

clear model;  #Used when running multiple times to clear the model
model ./model/twoTask.mapl;    # link the model file

print "==================Solve using MindOpt Solver==================";
option solver mindopt;     # select the MindOpt solver
solve;  

print "-----------------Display---------------";
display; 
print "Objective = ";
print 100 * xa + 150 * xb;

# Change the solver

print "==================Solve using Cbc Solver==================";
option solver cbc;     # select the Cbc solver
solve; 

print "-----------------Display---------------";
display;   
print "Objective = ";
print 100 * xa + 150 * xb;

The Mindopt results of running the two methods above are consistent:

==================Solve using MindOpt Solver==================
Running mindoptampl
wantsol=1
mip_integer_tolerance=1e-9
MindOpt Version 0.24.1 (Build date: 20230423)
Copyright (c) 2020-2023 Alibaba Cloud.

Start license validation (current time : 10-MAY-2023 12:09:28).
License validation terminated. Time : 0.002s

Only one thread allowed -- optimize with Simplex method.
Model summary.
 - Num. variables     : 2
 - Num. constraints   : 1
 - Num. nonzeros      : 2
 - Bound range        : [3.0e+00,8.0e+00]
 - Objective range    : [1.0e+02,1.5e+02]
 - Matrix range       : [1.0e+00,1.0e+00]

Presolver started.
Model has been fully presolved.
Presolver terminated. Time : 0.000s

Simplex method started.
Model fingerprint: ==wZ3d2dnd3Z
Postsolver started.
Simplex method terminated. Time : 0.001s


OPTIMAL; objective 1050.00
0 simplex iterations

Completed.
-----------------Display---------------
Primal Solution:
xa       = 3.000000000000000E+00
xb       = 5.000000000000000E+00

Dual Solution:
Worker_time_1 = 1.500000000000000E+02
Objective = 
1050
==================Solve using Cbc Solver==================
Running cbc
CBC 2.10.5Completed.
-----------------Display---------------
Primal Solution:
xa       = 3.000000000000000E+00
xb       = 5.000000000000000E+00

Dual Solution:
Worker_time_1 = 1.500000000000000E+02
Objective = 
1050

3. The Result

After executing the model command, it converts the mathematical programming model declared in the .mapl file into a solver-understandable model.

More modeling codes can continue to be added.

After executing the solve command, MAPL generates twoTask.nl, which many solvers (including MindOpt) can take as input but is not very friendly for humans. The .nl file will be solved by MAPL automatically. Therefore, the user should not change the .nl file themselves.

After solving, MAPL also generates twoTask.sol, which is the solution of the problem. You can check the documentation for more details about the two files.

twoTask.mapl,twoTask.nl,twoTask.sol Files can be found in quick start view in case

After executing the display command, MAPL will display the result summary:

Primal Solution:
xa       = 3.000000000000000E+00
xb       = 5.000000000000000E+00

Dual Solution:
Worker_time_1 = 1.500000000000000E+02

Users can use print to print the values, such as the objective function.

Objective = 
1050

It shows that the optimal value of the decision variable xa is 3, and xb is 5. They are within their bounds and satisfy the constraint. Together, they give us the optimal objective value of 100xa + 150xb = 1050 yuan.

Worker_time represents the dual value corresponding to the constraint xa + xb = 8.

1 1 0
Share on

MindOpt

5 posts | 0 followers

You may also like

Comments

5605675938002332 August 24, 2023 at 6:34 am

Using MindOpt: https://opt.alibabacloud.com

MindOpt

5 posts | 0 followers

Related Products

  • Alibaba Cloud Academy

    Alibaba Cloud provides beginners and programmers with online course about cloud computing and big data certification including machine learning, Devops, big data analysis and networking.

    Learn More
  • CloudBox

    Fully managed, locally deployed Alibaba Cloud infrastructure and services with consistent user experience and management APIs with Alibaba Cloud public cloud.

    Learn More
  • Alibaba Cloud Flow

    An enterprise-level continuous delivery tool.

    Learn More