Пример #1
0
 def test_decompose1(self):
   model = MPModelBuilder.build_from_scratch(
     [8, 2, 5, 5, 8, 3, 9, 7, 6],
     [[2, 3, 4, 1, 0, 0, 0, 0, 0],
      [1, 2, 3, 2, 0, 0, 0, 0, 0],
      [0, 0, 1, 4, 3, 4, 2, 0, 0],
      [0, 0, 2, 1, 1, 2, 5, 0, 0],
      [0, 0, 0, 0, 0, 0, 2, 1, 2],
      [0, 0, 0, 0, 0, 0, 3, 4, 1]],
     ['L'] * 6,
     [7, 6, 9, 7, 3, 5])
   decomposer = finkelstein_qb_decomposer.FinkelsteinQBDecomposer(model)
   decomposer.decompose()
   u = [set([0, 1]), set([2, 3]), set([4, 5])]
   s = [set([]), set([2, 3]), set([6])]
   m = [set([0, 1]), set([4, 5]), set([8, 7])]
   for t, r in ((u, decomposer._u), (s, decomposer._s), (m, decomposer._m)):
     self.assert_equal(len(t), len(r))
     for i in range(len(t)):
       self.assert_equal(t[i], r[i])
   tree = decomposer.get_decomposition_tree()
   p0 = tree.node[tree.get_root()].get_model()
   self.assert_equal([u'x7', u'x8', u'x9'], sorted(p0.get_columns_names()))
   p1 = tree.node[tree.neighbors(tree.get_root())[0]].get_model()
   self.assert_equal([u'x3', u'x4', u'x5', u'x6', u'x7'],
                     sorted(p1.get_columns_names()))
 def test_decompose1(self):
   model = MPModelBuilder.build_from_scratch(
     [8, 2, 5, 5, 8, 3, 9, 7, 6],
     [[2, 3, 4, 1, 0, 0, 0, 0, 0],
      [1, 2, 3, 2, 0, 0, 0, 0, 0],
      [0, 0, 1, 4, 3, 4, 2, 0, 0],
      [0, 0, 2, 1, 1, 2, 5, 0, 0],
      [0, 0, 0, 0, 0, 0, 2, 1, 2],
      [0, 0, 0, 0, 0, 0, 3, 4, 1]],
     ['L'] * 6,
     [7, 6, 9, 7, 3, 5])
   decomposer = finkelstein_adv_decomposer.FinkelsteinAdvDecomposer(model)
   decomposer.decompose()
   
   layer = [[set([0,1,2,3])], [set([2,3,4,5,6])], [set([6,7,8])]]
   self.assert_equal(len(layer),len(decomposer._layers))
   for i in range(len(layer)):
     self.assert_equal(len(layer[i]),len(decomposer._layers[i]))
     for j in range(len(layer[i])):
       self.assert_equal(layer[i][j],decomposer._layers[i][j])
   
   tree = decomposer.get_decomposition_tree()
   
   p0=tree.node[tree.get_root()].get_model()
   self.assert_equal([u'x1',u'x2',u'x3',u'x4'],sorted(p0.get_columns_names()))
   p1=tree.node[tree.neighbors(tree.get_root())[0]].get_model()
   self.assert_equal([u'x3',u'x4',u'x5',u'x6',u'x7'],sorted(p1.get_columns_names()))
 def test_decompose2(self):
   model = MPModelBuilder.build_from_scratch(
     [1, 1, 1, 1, 1, 1, 1 ],
     [[1, 1, 1, 0, 0, 0, 0],
      [0, 1, 0, 1, 1, 0, 0],
      [0, 0, 1, 0, 0, 1, 1]],
     ['L'] * 3,
     [2, 2, 2])
   decomposer = finkelstein_adv_decomposer.FinkelsteinAdvDecomposer(model)
   decomposer.decompose()
   
   tree = decomposer.get_decomposition_tree()
   
   layer = [[set([0,1,2])], [set([1,3,4]), set([2,5,6])]]
   self.assert_equal(len(layer),len(decomposer._layers))
   for i in range(len(layer)):
     self.assert_equal(len(layer[i]),len(decomposer._layers[i]))
     for layers1, layers2 in ( (layer[i], decomposer._layers[i]) ,(decomposer._layers[i],layer[i]) ):
       for j in range(len(layers1)):
         ok=False
         for k in range(len(layers2)):
           if layers2[k]==layers1[j]:
             ok=True
         if not ok:
           print(layers1[j])
           print(layers2)
         self.assert_equal(ok,True)
Пример #4
0
 def test_decompose2(self):
   model = MPModelBuilder.build_from_scratch(
     [2, 3, 1, 5, 4, 6, 1],
     [[3., 4., 1., 0., 0., 0., 0.],
      [0., 2., 3., 3., 0., 0., 0.],
      [0., 2., 0., 0., 3., 0., 0.],
      [0., 0., 2., 0., 0., 3., 2.]],
     ['L'] * 4,
     [6, 5, 4, 5])
   decomposer = finkelstein_qb_decomposer.FinkelsteinQBDecomposer(model)
   decomposer.decompose()
   u = [set([0]), set([1, 2, 3])]
   s = [set([]), set([1, 2])]
   m = [set([0]), set([3, 4, 5, 6])]
   for t, r in ((u, decomposer._u), (s, decomposer._s), (m, decomposer._m)):
     self.assert_equal(len(t), len(r))
     for i in range(len(t)):
       self.assert_equal(t[i], r[i])
Пример #5
0
  def test_decompose3(self):
    model = MPModelBuilder.build_from_scratch(
      [1, 1, 1, 1, 1],
      [[1, 1, 0, 0, 0],
       [0, 1, 1, 0, 0],
       [0, 0, 1, 1, 0],
       [0, 0, 0, 1, 1]],
      ['L'] * 4,
      [1, 1, 1,1])
    decomposer = finkelstein_qb_decomposer.FinkelsteinQBDecomposer(model)
    decomposer.decompose()

    u = [set([0]), set([1]), set([2]),set([3])]
    s = [set([]), set([1]), set([2]),set([3])]
    m = [set([0]), set([]), set([]), set([4])]
    for t, r in ((u, decomposer._u), (s, decomposer._s), (m, decomposer._m)):
      self.assert_equal(len(t), len(r))
      for i in range(len(t)):
        self.assert_equal(t[i], r[i])
    tree = decomposer.get_decomposition_tree()
Пример #6
0
 def test_build(self):
   model = MPModelBuilder.build_from_scratch(
     [8, 2, 5, 5, 8, 3, 9, 7, 6],
     [[2., 3., 4., 1., 0., 0., 0., 0., 0.],
      [1., 2., 3., 2., 0., 0., 0., 0., 0.],
      [0., 0., 1., 4., 3., 4., 2., 0., 0.],
      [0., 0., 2., 1., 1., 2., 5., 0., 0.],
      [0., 0., 0., 0., 0., 0., 2., 1., 2.],
      [0., 0., 0., 0., 0., 0., 3., 4., 1.]],
     ["L"] * 6,
     [7, 6, 9, 7, 3, 5])
   self.assert_equal(9, model.get_num_columns())
   self.assert_equal(6, model.get_num_rows())
   self.assert_equal(["c1", "c2", "c3", "c4", "c5", "c6"], model.rows_names)
   self.assert_equal([8, 2, 5, 5, 8, 3, 9, 7, 6],
                     model.get_objective_coefficients())
   self.assert_equal(["x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9"],
                     model.columns_names)
   self.assert_equal([0.0] * 9, model.columns_lower_bounds)
   self.assert_equal([1.0] * 9, model.columns_upper_bounds)