Example 1 (Dual-task assignment) only has two tasks for the assignment. Next, we will consider a more complex situation with more tasks.
Consider a multi-task assignment scenario where the employee needs to handle m tasks a day, the hourly compensation for each task i is ri, and the hours spent on each task i should be at least ℓi but no more than ui. Knowing that the employee works b hours each day, how should he allocate his time to receive the most compensation while fulfilling the factory requirements? This problem is a generalization of the dual-task assignment problem in the previous section.
Introduce a variable xi for the hours spent on each task i. From the problem description, the variables must satisfy the constraint and the bounds ℓi ≤ xi ≤ui, ∀i∈{1,2,⋯,m}. The objective is to maximize the total compensation . Putting them together, we obtain:
Compared with the dual-task assignment model, this model has the following differences:
MAPL modeling requires specific values of parameters (such as data). MAPL has two ways to read data:
The first one is easier to use when the mathematical planning problem model is smaller, while the second one is more suitable for larger problems.
This section focuses on the case where the data and model are in the same file.
Run the codes in the following cell:
clear model; #Used when running multiple times to clear the model
option modelname model/multiTask; #Facilitate the generation of intermediate files in the same directory as Method 2.
#--------------------------
# multiTask.mapl
set Tasks := { 1 .. 10 }; # Declare the set Tasks
param Reward[Tasks] := 1:2, 3: 3, 7:4 default 1; # Declare the parameter Reward and assign a value
param LB[Tasks] := 1 : 1, 3: 1 default 0; # Declare the lower bound LB and assign a value
param UB[Tasks] := 3: 4, 7: 2 default 8; # Declare the upper bound UB and assign a value
param b := 8; # Declare the total working hours of the employee
var x[i in Tasks] >= LB[i] <= UB[i]; # Declare the variable LB[i] <= x[i] <= UB[i]
maximize Total_Reward: sum{i in Tasks} Reward[i] * x[i]; # Declare the target function
subto Worker_time: sum{i in Tasks} x[i] == b; # declaration constraint sum_i x[i] == 8
#--------------------------
print "-----------------Solving---------------";
option solver mindopt; # (Optional) Specify the solver for solving, the default is MindOpt
solve;
print "-----------------Display---------------";
display; # Show Results
print "Total_Reward: ", sum {i in Tasks} Reward[i] * x[i];
print "Work time: ", sum {i in Tasks} x[i] ;
We can also save the modeling part codes in file multiTask.mapl
. and call MAPL to load the file:
clear model; #Used when running multiple times to clear the model
#--------------------------
model ./model/multiTask.mapl;
#--------------------------
print "-----------------Solving---------------";
#option solver mindopt; # (Optional) Specify the solver for solving, the default is MindOpt
option solver cbc; # Use Cbc solver
solve;
print "-----------------Display---------------";
display; # Show Results
print "Total_Reward: ", sum {i in Tasks} Reward[i] * x[i];
print "Work time: ", sum {i in Tasks} x[i] ;
The results of Method 1 and Method 2 are consistent:
-----------------Solving---------------
Running mindoptampl
wantsol=1
MindOpt Version 0.25.1 (Build date: 20230816)
Copyright (c) 2020-2023 Alibaba Cloud.
Start license validation (current time : 24-AUG-2023 16:07:57).
License validation terminated. Time : 0.004s
Model summary.
- Num. variables : 10
- Num. constraints : 1
- Num. nonzeros : 10
- Bound range : [1.0e+00,8.0e+00]
- Objective range : [1.0e+00,4.0e+00]
- Matrix range : [1.0e+00,1.0e+00]
Presolver started.
Presolver terminated. Time : 0.000s
Simplex method started.
Model fingerprint: ==gZ3F2dhdnZ
Iteration Objective Dual Inf. Primal Inf. Time
0 5.25006e+01 0.0000e+00 2.3400e+01 0.00s
1 2.40000e+01 0.0000e+00 0.0000e+00 0.00s
Postsolver started.
Simplex method terminated. Time : 0.001s
OPTIMAL; objective 24.00
1 simplex iterations
Completed.
-----------------Display---------------
Primal Solution:
x@1 = 2.00000000
x@2 = 0.00000000
x@3 = 4.00000000
x@4 = 0.00000000
x@5 = 0.00000000
x@6 = 0.00000000
x@7 = 2.00000000
x@8 = 0.00000000
x@9 = 0.00000000
x@10 = 0.00000000
Total_Reward: 24
Work time: 8
----------------------------------------
-----------------Solving---------------
Running cbc
CBC 2.10.5Completed.
-----------------Display---------------
Primal Solution:
x@1 = 2.000000000000000E+00
x@2 = 0.000000000000000E+00
x@3 = 4.000000000000000E+00
x@4 = 0.000000000000000E+00
x@5 = 0.000000000000000E+00
x@6 = 0.000000000000000E+00
x@7 = 2.000000000000000E+00
x@8 = 0.000000000000000E+00
x@9 = 0.000000000000000E+00
x@10 = 0.000000000000000E+00
Dual Solution:
Worker_time_1 = 2.000000000000000E+00
Total_Reward: 24
Work time: 8
Print x@name
is the value of the decision variable, followed by the dual solution.
This result indicates that when allocating 2 hours to task 1, 4 hours to task 3, and 2 hours to task 7, the maximum profit is achieved with an objective value of 24.00.
Solving Task Assignment Problems (Getting Started with Mindopt)
MindOpt - August 24, 2023
MindOpt - August 29, 2023
MindOpt - August 29, 2023
MindOpt - August 29, 2023
Richard Kou - February 20, 2021
Alibaba Cloud Product Launch - December 12, 2018
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 MoreFully managed, locally deployed Alibaba Cloud infrastructure and services with consistent user experience and management APIs with Alibaba Cloud public cloud.
Learn MoreAn enterprise-level continuous delivery tool.
Learn More