11#!/usr/bin/python
22# -*- coding: utf-8 -*-
33
4- import pdb
54from mip .model import *
65
76EPS = 10e-4
87SOLVER = GUROBI
98
9+ def get_pricing (m , w , L ):
10+ # creating the pricing problem
11+ pricing = Model (SOLVER )
12+
13+ # creating pricing variables
14+ a = []
15+ for i in range (m ):
16+ a .append (pricing .add_var (obj = 0 , var_type = INTEGER , name = 'a_%d' % (i + 1 )))
17+
18+ # creating pricing constraint
19+ pricing .add_constr (xsum (w [i ] * a [i ] for i in range (m )) <= L , 'bar_length' )
20+
21+ pricing .write ('pricing.lp' )
22+
23+ return a , pricing
1024
1125def cg ():
1226 """
@@ -32,19 +46,6 @@ def cg():
3246 for i in range (m ):
3347 constraints .append (master .add_constr (lambdas [i ] >= b [i ], name = 'i_%d' % (i + 1 )))
3448
35- # creating the pricing problem
36- pricing = Model (SOLVER )
37-
38- # creating pricing variables
39- a = []
40- for i in range (m ):
41- a .append (pricing .add_var (obj = 0 , var_type = INTEGER , name = 'a_%d' % (i + 1 )))
42-
43- # creating pricing constraint
44- pricing .add_constr (xsum (w [i ] * a [i ] for i in range (m )) <= L , 'bar_length' )
45-
46- pricing .write ('pricing.lp' )
47-
4849 new_vars = True
4950 while new_vars :
5051
@@ -65,6 +66,8 @@ def cg():
6566 # STEP 2: updating pricing objective with dual values from master
6667 ##########
6768
69+ a , pricing = get_pricing (m , w , L )
70+
6871 pricing .objective = 1
6972 for i in range (m ):
7073 a [i ].obj = - constraints [i ].pi
@@ -86,7 +89,7 @@ def cg():
8689
8790 # checking if columns with negative reduced cost were produced and
8891 # adding them into the restricted master problem
89- if pricing .objective_value < - EPS :
92+ if 1 + pricing .objective_value < - EPS :
9093 coeffs = [a [i ].x for i in range (m )]
9194 column = Column (constraints , coeffs )
9295 lambdas .append (master .add_var (obj = 1 , column = column , name = 'lambda_%d' % (len (lambdas ) + 1 )))
@@ -99,7 +102,6 @@ def cg():
99102 new_vars = False
100103
101104 pricing .write ('pricing.lp' )
102- pdb .set_trace ()
103105
104106 print_solution (master )
105107
0 commit comments