Esempio n. 1
0
def test_ampl_eval_error():
    with util.AMPL() as ampl:
        error = None
        try:
            ampl.eval_expr('1000 ^ 1000')
        except util.AMPLError as e:
            error = e
        assert 'Numerical result out of range' in str(error)
Esempio n. 2
0
def test_ampl_eval_error():
  with util.AMPL() as ampl:
    error = None
    try:
      ampl.eval_expr('1000 ^ 1000')
    except util.AMPLError as e:
      error = e
    assert 'Numerical result out of range' in str(error)
Esempio n. 3
0
def read_solution(ampl_filename, sol_filename):
  """
  Read the solution of the model *ampl_filename* from *sol_filename*
  and returns the objective value.
  """
  sol = Solution()
  dirname, filename = os.path.split(ampl_filename)
  with AMPL(dirname) as ampl:
    ampl.eval('model "{}";'.format(ampl_filename))
    ampl.eval('solution "{}";'.format(sol_filename))
    try:
      sol.obj = float(ampl.eval_expr('_obj[1]'))
    except AMPLError as e:
      sol.obj = 'nan'
      sol.obj_error = str(e)
    sol.solve_result = ampl.eval_expr('solve_result')
    sol.solve_message = ampl.eval_expr('solve_message')
  return sol
Esempio n. 4
0
def read_solution(ampl_filename, sol_filename):
    """
  Read the solution of the model *ampl_filename* from *sol_filename*
  and returns the objective value.
  """
    sol = Solution()
    dirname, filename = os.path.split(ampl_filename)
    with AMPL(dirname) as ampl:
        ampl.eval('model "{}";'.format(ampl_filename))
        ampl.eval('solution "{}";'.format(sol_filename))
        try:
            sol.obj = float(ampl.eval_expr('_obj[1]'))
        except AMPLError as e:
            sol.obj = 'nan'
            sol.obj_error = str(e)
        sol.solve_result = ampl.eval_expr('solve_result')
        sol.solve_message = ampl.eval_expr('solve_message')
    return sol
Esempio n. 5
0
def test_ampl():
    with util.AMPL() as ampl:
        assert ampl.eval('print 42;') == [('print', '42\n')]
        assert ampl.eval_expr(42) == 42
Esempio n. 6
0
def test_ampl():
  with util.AMPL() as ampl:
    assert ampl.eval('print 42;') == [('print', '42\n')]
    assert ampl.eval_expr(42) == 42