Пример #1
0
 def combine_problems(dirname):
   composite_index = OrderedDict()
   for indices in combinations:
     merged_model, best_obj = merge_models([index[i] for i in indices])
     name = '-'.join(['{:02}'.format(i + 1) for i in indices])
     filename = name + '.mod'
     path = os.path.join(dirname, filename)
     with open(path, 'w') as f:
       ampl.pretty_print(f, merged_model)
     composite_index[name] = {'best_obj': best_obj, 'path': path}
   return composite_index
Пример #2
0
def test_merge_models():
    index = util.load_index('casado')
    stmt, best_obj = util.merge_models([index['casado01'], index['casado03']])
    output = StringIO()
    ampl.pretty_print(output, stmt)
    assert output.getvalue() == \
  """var x1 in [0, 20];
var x2 in [-10, 10];
minimize f: ((exp(-3 * x1) - sin(x1) ^ 3) + 1.0) * ((x2 - x2 ^ 2) ^ 2 + (x2 - 1) ^ 2);
"""
    assert best_obj == 0
Пример #3
0
def test_merge_models():
  index = util.load_index('casado')
  stmt, best_obj = util.merge_models([index['casado01'], index['casado03']])
  output = StringIO()
  ampl.pretty_print(output, stmt)
  assert output.getvalue() == \
"""var x1 in [0, 20];
var x2 in [-10, 10];
minimize f: ((exp(-3 * x1) - sin(x1) ^ 3) + 1.0) * ((x2 - x2 ^ 2) ^ 2 + (x2 - 1) ^ 2);
"""
  assert best_obj == 0
Пример #4
0
 def combine_problems(dirname):
     composite_index = OrderedDict()
     for indices in combinations:
         merged_model, best_obj = merge_models([index[i] for i in indices])
         name = '-'.join(['{:02}'.format(i + 1) for i in indices])
         filename = name + '.mod'
         path = os.path.join(dirname, filename)
         with open(path, 'w') as f:
             ampl.pretty_print(f, merged_model)
         composite_index[name] = {'best_obj': best_obj, 'path': path}
     return composite_index
Пример #5
0
def check_print(output, node):
  "Check if the output of pretty_print for the given AST node."
  stream = StringIO()
  ampl.pretty_print(stream, node)
  real_output = stream.getvalue()
  assert real_output == output