0% found this document useful (0 votes)
0 views5 pages

Constraint__Integer_programming

The document discusses two methods for solving a transportation problem using the ortools library: Constraint Programming and Integer Programming. It outlines the modeling of variables, constraints, and the objective function for each method. Both approaches aim to optimize the movement of a bus between various points while adhering to specified constraints.

Uploaded by

nguyenly2k5.vn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views5 pages

Constraint__Integer_programming

The document discusses two methods for solving a transportation problem using the ortools library: Constraint Programming and Integer Programming. It outlines the modeling of variables, constraints, and the objective function for each method. Both approaches aim to optimize the movement of a bus between various points while adhering to specified constraints.

Uploaded by

nguyenly2k5.vn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

2.1.2.

Constraint Programming
In this method, we first model the problem and use the help of
ortools library to solve it.
The following is how we model and implement the code:
(1) Firstly, we set variables for our problem:
x [ i , j ] =1 , means thebus move ¿ point i¿ point j ( x [ i , j ] =0 otherwise ) ∀ i , j∈[0 , 2 n]
u [ i ] =l, means the load of bus after leaving point i isl with l∈ [ 1 , k ] , ∀ i ∈[1 , n]
u [ i ] =l, means the load of bus after leaving point i isl with l∈ [ 0 , k−1 ] , ∀ i∈[n+1 , 2 n]
index [ i ] =p ,means the order of visiting point iis p with p ∈ [ 1 , 2n ] , ∀ i∈[1, 2 n]

(2) After that, we model our constraint and implement the


code for each constraint:
Constraint 1: each point visit by only 1 point and from each point move to exactly
1 point
2n 2n

∑ x [i , j]=∑ x [ j , i]=1 ∀ j∈ [ 0 ,2 n ]∧i ≠ j


i=0 i=0
Constraint 2: pick when move to a pickup point
u [ i ] +1=u [ j ] ∀ i∈ [ 0 , 2 n ] , j∈ [ 1, n ] , if x [ i , j ] =1

Constraint 3: drop when move to a drop point


u [ i ] −1=u [ j ] ∀ i∈ [ 1, 2 n ] , j∈ [ n+1 ,2 n ] , if x [ i , j ] =1

Constraint 4: can not return to point 0 from a pick up point and can not move to a
drop point from start point
x [ i , 0 ] =x [ 0 , i+n ] =0 ∀ i∈[1 , n]

Constraint 5: index of a pickup point < index of its corresponding drop point
index [ i+ n ] >index [ i ] ∀ i ∈[1 , n]

Constraint 6: flow constraint


index [ i ] +1=index [ j ] if x [ i. j ] =1 ∀ i, j ∈[1 , 2 n]
(3) Finally, we define the objective function that depends
on the declare variables as follow:

After modeling, all the variables, constraints with


objective function have been added to the solver. Now we
use the ortools to solve and gain the solution:

2.1.3. Integer Programming


With the same approach with Constraint Programming, we use
ortools to solve but we must model the problem in different way.
(1) First, we also set the variable:
x [ i , j ] =1 , means thebus move ¿ point i¿ point j ( x [ i , j ] =0 otherwise ) ∀ i , j∈[0 , 2 n]
u [ i ] =l, means the load of bus after leaving point i isl with l∈ [ 1 , k ] , ∀ i ∈[1 , n]
u [ i ] =l, means the load of bus after leaving point i isl with l∈ [ 0 , k−1 ] , ∀ i∈[n+1 , 2 n]
index [ i ] =p ,means the order of visiting point iis p with p ∈ [ 1 , 2n ] , ∀ i∈[1, 2 n]
(2) The constraints:
2n 2n
 ∑ x [i , j]=∑ x [ j , i]=1 ∀ j∈ [ 0 ,2 n ]∧i ≠ j
i=0 i=0


{ M ( 1−x [ i, j ]) +u [ i ] −u [ j ] ≥−1 ∀ i∈ [ 0 ,2 n ] , j ∈ [ 1 ,n ]
M ( 1−x [ i, j ]) +u [ j ] −u [ i ] ≥ 1


{ M ( 1−x [ i, j ] ) +u [ i ] −u [ j ] ≥ 1 ∀ i∈ [ 1 , 2 n ] , j∈ [ n+1 ,2 n ]
M ( 1−x [ i, j ] ) +u [ j ]−u [ i ] ≥−1
 x [ i , 0 ] =x [ 0 , i+n ] =0 ∀ i∈ [ 1, n ]
 index [ i+ n ] −index [ i ] −h ≥ 0 ∀ i ∈ [ 1 ,n ] ;(h ∈ N , h ≥1 is a slack variable )


{ M ( 1−x [ i, j ]) +index [ i ] −index [ j ] ≥−1 ∀ i ∈ [ 1 ,2 n ] , j∈ [ 1 ,2 n ]
M ( 1−x [ i, j ]) +index [ j ]−index [ i ] ≥ 1
(3) And finally, the objective function:
2n 2n
Total=∑ ∑ x [ i, j ]∗distance [ i , j ] if i≠ j
i=0 j=0

We add our model to the SAT solver in ortools library to


solve and give us the solution.

You might also like