Reputation: 1
Does anyone know how to define dependent sets on Lingo? For example: A company has 5 plants. Each plant has a different number of machines, i.e., 3, 4, 5, 2, 3, respectively. The company gets 20 orders. They should assign each order to the plants and machines. Cost is only dependent on which plant the order is processed. How should I define the set for the machines that dependent on the plants?
If I use the model below, it will define that all plants have 17 machines. Meanwhile, what I want to set is that the 1st-3rd machines belong to the 1st plant and so on so that the 15th-17th machines belong to the 5th plant. Alternatively, the indices of the machines for each plant are 1..3, 1..4, 1..5, 1..2, and 1..3, respectively. How should I define the set for the machines?
Model:
Sets:
orders/1..20/:;
plants/1..5/:;
machines/1..17/:;
allocation(orders, plants): c;
assign(orders, plants, machines): x;
end sets
data:
c = 1 2 3 4 5
6 7 8 9 10
10 9 8 7 6
5 4 3 2 1
1 2 3 4 5
6 7 8 9 10
10 9 8 7 6
5 4 3 2 1
1 2 3 4 5
6 7 8 9 10
10 9 8 7 6
5 4 3 2 1
1 2 3 4 5
6 7 8 9 10
10 9 8 7 6
5 4 3 2 1
1 2 3 4 5
6 7 8 9 10
10 9 8 7 6
5 4 3 2 1;
end data
min = @sum(assign(i, j, k): c(i, j) * x(i, j, k));
@for(orders(i): @sum(plants(j): @sum(machines(k): x(i, j, k))) = 1);
@for(assign(i, j, k): @bin(x(i, j, k)));
end
Thank you, Tantrika
Upvotes: 0
Views: 69
Reputation: 1
I think you got a wrong modelling. Based on your model, total you have 5 plant x 20 order x 17 machine=1700 machine variables to assign. However, I think I got your point that several plant may acquired 3-4 machines. The modelling are presented as follows:
Sets:
orders/1..20/:;
plants/1..5/:;
machines/1..4/:;
allocation(orders, plants): c;
assign(orders, plants, machines): x;
end sets
data:
c = 1 2 3 4 5
6 7 8 9 10
10 9 8 7 6
5 4 3 2 1
1 2 3 4 5
6 7 8 9 10
10 9 8 7 6
5 4 3 2 1
1 2 3 4 5
6 7 8 9 10
10 9 8 7 6
5 4 3 2 1
1 2 3 4 5
6 7 8 9 10
10 9 8 7 6
5 4 3 2 1
1 2 3 4 5
6 7 8 9 10
10 9 8 7 6
5 4 3 2 1;
end data
!objective function;
min = @sum(assign(i,j,k):c(i, j) * x(i,j,k));
!an order should be assigned to a certain machine in a specific plants;
@for(orders(i): @sum(plants(j):@sum(machines(k):x(i,j,k)))<=1);
!all machines have to fullfill order;
@sum(assign(i,j,k): x(i,j,k))>=17;
!a machine is assigned using binary;
@for(assign(i,j,k): @bin(x(i, j, k)));
!plant 1, 2, and 5 only have 3 machines;
@for(orders(i):@for(plants(j)| j #EQ# 1: @for(machines(k)| k #EQ# 4:x(i, j, k)=0)));
@for(orders(i):@for(plants(j)|j#EQ#2: @for(machines(k)|k#EQ#4:x(i, j, k)=0)));
@for(orders(i):@for(plants(j)|j#EQ#5: @for(machines(k)|k#EQ#4:x(i, j, k)=0)));
!dummy variable to detect how many machines;
xx=@sum(assign(i,j,k): x(i,j,k));
xx>=0;
end
Upvotes: 0