×
Community Blog Mindopt Modeling Solving Task Assignment Problems (III)

Mindopt Modeling Solving Task Assignment Problems (III)

This article discusses the composite set (multidimensional sets) and multiple summation functions in MindOpt APL.

Multi-Person Multi-Task Assignment

This example further complicates the problem, using the composite set (multidimensional sets) and multiple summation functions in MindOpt APL.

1. Problem Description

Suppose a factory needs to assign n employees to do m tasks every day. Due to the difference in the technical ability of each worker, when the j employee participates in the i task, the factory can earn a profit of rij yuan for each hour of work. In addition, each task i requires the total working hours (Note: The total working hours are defined as the sum of the hours each worker participates in the task), not more than ui hours and not less than li hours. Given that each employee's daily working hours are b per hour, how should the factory assign the working hours of each task to n employees so the factory can obtain the maximum profit under the conditions of meeting each constraint?

This problem is expanded based on the single-person multi-tasking problem in the previous section. When a single person is assigned to multiple tasks, the goal is often to maximize the individual's reward. In the case of multi-tasking, the goal is often to maximize the profits of an organization (such as a factory). Another difference is that when assigning multiple people to multiple tasks, the total working hours for each task will include the length of time each worker participated in the contribution.

2. Mathematical Programming Model

We introduce a decision variable, xij, to represent the number of hours an employee j devotes to task i. The problem description above makes it clear that these variables need to satisfy 3 constraints:

1.  Each employee's daily working hours are b:

1

2.  Each task's daily total working hours have upper and lower boundary requirements:

2

3.  Employees j input task i in man-hours, and xij is non-negative:

3

In addition, the plant's goal is to maximize profits

4

Based on these elements, we obtain the following mathematical planning model:

5

Two sets are used in the model to represent the set of employees and the set of tasks, respectively. Corresponding to these two sets are two indexes. In addition, the total working hours of each task need to count the length of time each employee participates in the input, so the constraint is not the decision variable xij, the own upper and lower bound constraint, which needs to use MAPL special statement.

3. MAPL coding

Next, we will model the problem with a separated data file.

3.1 Prepare Data File

First, we prepare the data file:

multiStaffTask_tasks.txt

1,2,3,4,5

multiStaffTask_workers.txt

1,2,3

multiStaffTask_LB.txt

1,1
2,1
3,2
4,2
5,1

multiStaffTask_UB.txt

1,3
2,8
3,4
4,4
5,8

multiStaffTask_reward.txt

1,1,1
1,2,1
1,3,4
2,1,1
2,2,1
2,3,1
3,1,2
3,2,1
3,3,1
4,1,1
4,2,1
4,3,1
5,1,3
5,2,1
5,3,2

3.2. Call MAPL

Next, we can read the data files above in MAPL and model them:

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

#--------------------------
# multiStaffTask.mapl
# The absolute path of the input data file.
param Dir := "./model";
param Tasks_File := Dir + "/multiStaffTask_tasks.txt";
param Workers_File := Dir + "/multiStaffTask_workers.txt";
param Reward_File := Dir + "/multiStaffTask_reward.txt";
param UB_File := Dir + "/multiStaffTask_UB.txt";
param LB_File := Dir + "/multiStaffTask_LB.txt";

# Declaration parameters
set Tasks := { read Tasks_File as "<n+>"};
set Workers := { read Workers_File as "<n+>"};
param Reward[Tasks * Workers] := read Reward_File as "<1n, 2n> 3n";
param UB[Tasks] := read UB_File as "<1n> 2n";
param LB[Tasks] := read LB_File as "<1n> 2n";
param b := 8; 

# Declare variables
var x[Tasks * Workers] >= 0;

# Declare target
maximize Total_Reward: sum {<i, w> in Tasks * Workers} Reward[i, w] * x[i, w]; 

# Declare constraints
subto Worker_time: 
  forall {w in Workers }
  sum {i in Tasks} x[i, w] == b;   
  
subto Task_time:
  forall {i in Tasks}
  LB[i] <= sum {w in Workers} x[i, w]<=UB[i];   
#--------------------------

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, w> in Tasks * Workers} Reward[i, w] * x[i, w];

3.3. Or Load the .mapl File

We can also save the code of the modeling part as a multiStaffTask.mapl file and call MAPL to load the file. In this operation method, we replaced the Cbc solver to solve the problem:

clear model;  #Used when running multiple times to clear the model

#--------------------------
model ./model/multiStaffTask.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, w> in Tasks * Workers} Reward[i, w] * x[i, w];

4. Results

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:03:31).
License validation terminated. Time : 0.005s

Model summary.
 - Num. variables     : 15
 - Num. constraints   : 8
 - Num. nonzeros      : 30
 - 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.001s

Simplex method started.
Model fingerprint: md3ZkdnYmd3b

    Iteration       Objective       Dual Inf.     Primal Inf.     Time
            0     1.20203e+02      0.0000e+00      1.1400e+02     0.01s    
           10     4.90000e+01      0.0000e+00      0.0000e+00     0.01s    
Postsolver started.
Simplex method terminated. Time : 0.006s


OPTIMAL; objective 49.00
10 simplex iterations

Completed.
-----------------Display---------------
Primal Solution:
 x@<1,1> = 0.00000000
 x@<1,2> = 0.00000000
 x@<1,3> = 3.00000000
 x@<2,1> = 0.00000000
 x@<2,2> = 6.00000000
 x@<2,3> = 2.00000000
 x@<3,1> = 0.00000000
 x@<3,2> = 2.00000000
 x@<3,3> = 0.00000000
 x@<4,1> = 0.00000000
 x@<4,2> = 0.00000000
 x@<4,3> = 3.00000000
 x@<5,1> = 8.00000000
 x@<5,2> = 0.00000000
 x@<5,3> = 0.00000000
Total_Reward : 49

-------------------Cbc----------------------------
-----------------Solving---------------
Running cbc
CBC 2.10.5Completed.
-----------------Display---------------
Primal Solution:
x@<1,1>  = 0.000000000000000E+00
x@<1,2>  = 0.000000000000000E+00
x@<1,3>  = 3.000000000000000E+00
x@<2,1>  = 0.000000000000000E+00
x@<2,2>  = 8.000000000000000E+00
x@<2,3>  = 0.000000000000000E+00
x@<3,1>  = 0.000000000000000E+00
x@<3,2>  = 0.000000000000000E+00
x@<3,3>  = 3.000000000000000E+00
x@<4,1>  = 0.000000000000000E+00
x@<4,2>  = 0.000000000000000E+00
x@<4,3>  = 2.000000000000000E+00
x@<5,1>  = 8.000000000000000E+00
x@<5,2>  = 0.000000000000000E+00
x@<5,3>  = 0.000000000000000E+00

Dual Solution:
Worker_time_1 = 2.000000000000000E+00
Worker_time_2 = 1.000000000000000E+00
Worker_time_3 = 1.000000000000000E+00
Task_time_1 = 3.000000000000000E+00
Task_time_2 = 0.000000000000000E+00
Task_time_3 = 0.000000000000000E+00
Task_time_4 = 0.000000000000000E+00
Task_time_5 = 1.000000000000000E+00
Total_Reward : 49

The display and print will show:

-----------------Display---------------
Primal Solution:
x@<1,1>  = 0.000000000000000E+00
x@<1,2>  = 0.000000000000000E+00
x@<1,3>  = 3.000000000000000E+00
x@<2,1>  = 0.000000000000000E+00
x@<2,2>  = 8.000000000000000E+00
x@<2,3>  = 0.000000000000000E+00
x@<3,1>  = 0.000000000000000E+00
x@<3,2>  = 0.000000000000000E+00
x@<3,3>  = 3.000000000000000E+00
x@<4,1>  = 0.000000000000000E+00
x@<4,2>  = 0.000000000000000E+00
x@<4,3>  = 2.000000000000000E+00
x@<5,1>  = 8.000000000000000E+00
x@<5,2>  = 0.000000000000000E+00
x@<5,3>  = 0.000000000000000E+00

Dual Solution:
Worker_time_1 = 2.000000000000000E+00
Worker_time_2 = 1.000000000000000E+00
Worker_time_3 = 1.000000000000000E+00
Task_time_1 = 3.000000000000000E+00
Task_time_2 = 0.000000000000000E+00
Task_time_3 = 0.000000000000000E+00
Task_time_4 = 0.000000000000000E+00
Task_time_5 = 1.000000000000000E+00
Total_Reward : 49

This result indicates:

Task 1 is allocated 3 hours by employee 3, Task 2 is allocated 8 hours by employee 2, Task 3 is allocated 3 hours by employee 3, Task 4 is allocated 2 hours by employee 3, and Task 5 is allocated 8 hours by employee 1.

Thus, the maximum total profit is achieved, which is 49.

0 0 0
Share on

MindOpt

5 posts | 0 followers

You may also like

Comments

MindOpt

5 posts | 0 followers

Related Products