コード例 #1
0
 def test_changing_variable_names_is_reflected_in_the_solver(self):
     model = Model(problem=glpk_read_cplex(TESTMODELPATH))
     for i, variable in enumerate(model.variables):
         variable.name = "var" + str(i)
         self.assertEqual(variable.name, "var" + str(i))
         self.assertEqual(glp_get_col_name(model.problem, variable._index),
                          "var" + str(i))
コード例 #2
0
 def test_get_primal(self):
     self.assertEqual(self.var.primal, None)
     model = Model(problem=glpk_read_cplex(TESTMODELPATH))
     model.optimize()
     for i, j in zip([var.primal for var in model.variables], [
             0.8739215069684306, -16.023526143167608, 16.023526143167604,
             -14.71613956874283, 14.71613956874283, 4.959984944574658,
             4.959984944574657, 4.959984944574658, 3.1162689467973905e-29,
             2.926716099010601e-29, 0.0, 0.0, -6.112235045340358e-30,
             -5.6659435396316186e-30, 0.0, -4.922925402711085e-29, 0.0,
             9.282532599166613, 0.0, 6.00724957535033, 6.007249575350331,
             6.00724957535033, -5.064375661482091, 1.7581774441067828, 0.0,
             7.477381962160285, 0.0, 0.22346172933182767,
             45.514009774517454, 8.39, 0.0, 6.007249575350331, 0.0,
             -4.541857463865631, 0.0, 5.064375661482091, 0.0, 0.0,
             2.504309470368734, 0.0, 0.0, -22.809833310204958,
             22.809833310204958, 7.477381962160285, 7.477381962160285,
             1.1814980932459636, 1.496983757261567, -0.0, 0.0,
             4.860861146496815, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
             5.064375661482091, 0.0, 5.064375661482091, 0.0, 0.0,
             1.496983757261567, 10.000000000000002, -10.0, 0.0, 0.0, 0.0,
             0.0, 0.0, -29.175827135565804, 43.598985311997524,
             29.175827135565804, 0.0, 0.0, 0.0, -1.2332237321082153e-29,
             3.2148950476847613, 38.53460965051542, 5.064375661482091, 0.0,
             -1.2812714099825612e-29, -1.1331887079263237e-29,
             17.530865429786694, 0.0, 0.0, 0.0, 4.765319193197458,
             -4.765319193197457, 21.79949265599876, -21.79949265599876,
             -3.2148950476847613, 0.0, -2.281503094067127,
             2.6784818505075303, 0.0
     ]):
         self.assertAlmostEqual(i, j)
コード例 #3
0
 def test_setting_bounds(self):
     model = Model(problem=glpk_read_cplex(TESTMODELPATH))
     var = model.variables[0]
     var.lb = 1
     self.assertEqual(var.lb, 1)
     self.assertEqual(glpk_interface.glp_get_col_lb(model.problem, var.index), 1)
     var.ub = 2
     self.assertEqual(var.ub, 2)
     self.assertEqual(glpk_interface.glp_get_col_ub(model.problem, var.index), 2)
コード例 #4
0
 def test_optimize_milp(self):
     problem = glpk_read_cplex(TESTMILPMODELPATH)
     milp_model = Model(problem=problem)
     milp_model.optimize()
     self.assertEqual(milp_model.status, 'optimal')
     self.assertAlmostEqual(milp_model.objective.value, 122.5)
     for variable in milp_model.variables:
         if variable.type == 'integer':
             self.assertEqual(variable.primal % 1, 0)
コード例 #5
0
 def test_get_primal(self):
     self.assertEqual(self.var.primal, None)
     model = glpk_interface.Model(problem=glpk_read_cplex(TESTMODELPATH))
     model.optimize()
     for i, j in zip([var.primal for var in model.variables],
                     [0.8739215069684306, -16.023526143167608, 16.023526143167604, -14.71613956874283,
                      14.71613956874283, 4.959984944574658, 4.959984944574657, 4.959984944574658,
                      3.1162689467973905e-29, 2.926716099010601e-29, 0.0, 0.0, -6.112235045340358e-30,
                      -5.6659435396316186e-30, 0.0, -4.922925402711085e-29, 0.0, 9.282532599166613, 0.0,
                      6.00724957535033, 6.007249575350331, 6.00724957535033, -5.064375661482091, 1.7581774441067828,
                      0.0, 7.477381962160285, 0.0, 0.22346172933182767, 45.514009774517454, 8.39, 0.0,
                      6.007249575350331, 0.0, -4.541857463865631, 0.0, 5.064375661482091, 0.0, 0.0,
                      2.504309470368734, 0.0, 0.0, -22.809833310204958, 22.809833310204958, 7.477381962160285,
                      7.477381962160285, 1.1814980932459636, 1.496983757261567, -0.0, 0.0, 4.860861146496815, 0.0,
                      0.0, 0.0, 0.0, 0.0, 0.0, 5.064375661482091, 0.0, 5.064375661482091, 0.0, 0.0,
                      1.496983757261567, 10.000000000000002, -10.0, 0.0, 0.0, 0.0, 0.0, 0.0, -29.175827135565804,
                      43.598985311997524, 29.175827135565804, 0.0, 0.0, 0.0, -1.2332237321082153e-29,
                      3.2148950476847613, 38.53460965051542, 5.064375661482091, 0.0, -1.2812714099825612e-29,
                      -1.1331887079263237e-29, 17.530865429786694, 0.0, 0.0, 0.0, 4.765319193197458,
                      -4.765319193197457, 21.79949265599876, -21.79949265599876, -3.2148950476847613, 0.0,
                      -2.281503094067127, 2.6784818505075303, 0.0]):
         self.assertAlmostEqual(i, j)
コード例 #6
0
 def setUp(self):
     self.model = Model(problem=glpk_read_cplex(TESTMODELPATH))
     self.obj = self.model.objective
コード例 #7
0
 def setUp(self):
     self.model = optlang.glpk_interface.Model(problem=glpk_read_cplex(TESTMODELPATH))
コード例 #8
0
 def setUp(self):
     self.model = self.interface.Model(problem=glpk_read_cplex(TESTMODELPATH))
     self.obj = self.model.objective
コード例 #9
0
 def test_changing_variable_names_is_reflected_in_the_solver(self):
     model = self.interface.Model(problem=glpk_read_cplex(TESTMODELPATH))
     for i, variable in enumerate(model.variables):
         variable.name = "var" + str(i)
         self.assertEqual(variable.name, "var" + str(i))
         self.assertEqual(glp_get_col_name(model.problem, variable._index), "var" + str(i))
コード例 #10
0
 def test_get_dual(self):
     self.assertEqual(self.var.dual, None)
     model = Model(problem=glpk_read_cplex(TESTMODELPATH))
     model.optimize()
     for i, j in zip([var.dual for var in model.variables], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.022916186593776235, 0.0, 0.0, 0.0, -0.03437427989066435, 0.0, -0.007638728864592075, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.005092485909728057, 0.0, 0.0, 0.0, 0.0, -0.005092485909728046, 0.0, 0.0, -0.005092485909728045, 0.0, 0.0, 0.0, -0.0611098309167366, -0.005092485909728045, 0.0, -0.003819364432296033, -0.00509248590972805, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.03946676580039239, 0.0, 0.0, -0.005092485909728042, -0.0, -0.0012731214774320113, 0.0, -0.0916647463751049, 0.0, 0.0, 0.0, -0.0, -0.04583237318755246, 0.0, 0.0, -0.0916647463751049, -0.005092485909728045, -0.07002168125876067, 0.0, -0.06874855978132867, -0.0012731214774320113, 0.0, 0.0, 0.0, -0.001273121477432006, -0.0038193644322960392, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.040739887277824405, -0.04583237318755245, -0.0012731214774320163, 0.0, 0.0, 0.0, 0.0, 0.0, -0.03437427989066435, 0.0, 0.0, -0.04837861614241648]):
         self.assertAlmostEqual(i, j)
コード例 #11
0
def test_glpk_read_cplex():
    problem = glpk_read_cplex(TESTMODELPATH)
    nose.tools.assert_equal(glp_get_num_rows(problem), 72)
    nose.tools.assert_equal(glp_get_num_cols(problem), 95)
コード例 #12
0
 def setUp(self):
     self.model = Model(problem=glpk_read_cplex(TESTMODELPATH))
     self.constraint = Constraint(Variable('chip') + Variable('chap'), name='woodchips', lb=100)
コード例 #13
0
 def test_setting_nonnumerical_bounds_raises(self):
     model = Model(problem=glpk_read_cplex(TESTMODELPATH))
     self.assertRaises(Exception, setattr, model.variables[0], 'lb', 'Chicken soup')
コード例 #14
0
 def test_setting_lower_bound_higher_than_upper_bound_raises(self):
     model = Model(problem=glpk_read_cplex(TESTMODELPATH))
     self.assertRaises(ValueError, setattr, model.variables[0], 'lb', 10000000000.)
コード例 #15
0
 def setUp(self):
     self.model = optlang.glpk_interface.Model(
         problem=glpk_read_cplex(TESTMODELPATH))
コード例 #16
0
ファイル: test_util.py プロジェクト: KristianJensen/optlang
def test_glpk_read_cplex():
    problem = glpk_read_cplex(TESTMODELPATH)
    nose.tools.assert_equal(glp_get_num_rows(problem), 72)
    nose.tools.assert_equal(glp_get_num_cols(problem), 95)
コード例 #17
0
 def setUp(self):
     problem = glpk_read_cplex(TESTMODELPATH)
     self.model = Model(problem=problem)