Ejemplo n.º 1
0
 def test_conopt_optimal(self):
     with ReaderFactory("sol") as reader:
         if reader is None:
             raise IOError("Reader 'sol' is not registered")
         soln = reader(join(currdir, "conopt_optimal.sol"))
         self.assertEqual(soln.solver.termination_condition,
                          TerminationCondition.optimal)
         self.assertEqual(soln.solution.status, SolutionStatus.optimal)
         self.assertEqual(soln.solver.status, SolverStatus.ok)
         self.assertTrue(check_optimal_termination(soln))
         assert_optimal_termination(soln)
Ejemplo n.º 2
0
    def test_infeasible1(self):
        with ReaderFactory("sol") as reader:
            if reader is None:
                raise IOError("Reader 'sol' is not registered")
            soln = reader(join(currdir, "infeasible1.sol"))
            self.assertEqual(soln.solver.termination_condition,
                             TerminationCondition.infeasible)
            self.assertEqual(soln.solution.status, SolutionStatus.infeasible)
            self.assertEqual(soln.solver.status, SolverStatus.warning)

            self.assertFalse(check_optimal_termination(soln))

            with self.assertRaises(RuntimeError):
                assert_optimal_termination(soln)
Ejemplo n.º 3
0
    def test_push_and_pop_oa_points(self):
        m = pe.ConcreteModel()
        m.x = pe.Var(bounds=(-2, 1))
        m.y = pe.Var()
        m.rel = coramin.relaxations.PWXSquaredRelaxation()
        m.rel.build(x=m.x, aux_var=m.y)
        m.obj = pe.Objective(expr=m.y)

        opt = pe.SolverFactory('gurobi_persistent')
        opt.set_instance(m)
        m.rel.add_persistent_solver(opt)

        res = opt.solve(save_results=False)
        assert_optimal_termination(res)
        self.assertAlmostEqual(m.x.value, -0.5)
        self.assertAlmostEqual(m.y.value, -2)

        m.x.value = -1
        m.rel.add_cut(keep_cut=True)
        res = opt.solve(save_results=False)
        assert_optimal_termination(res)
        self.assertAlmostEqual(m.x.value, 0)
        self.assertAlmostEqual(m.y.value, -1)

        m.rel.push_oa_points()
        m.rel.rebuild()
        res = opt.solve(save_results=False)
        assert_optimal_termination(res)
        self.assertAlmostEqual(m.x.value, 0)
        self.assertAlmostEqual(m.y.value, -1)

        m.rel.clear_oa_points()
        m.rel.rebuild()
        res = opt.solve(save_results=False)
        assert_optimal_termination(res)
        self.assertAlmostEqual(m.x.value, -0.5)
        self.assertAlmostEqual(m.y.value, -2)

        m.x.value = -0.5
        m.rel.add_cut(keep_cut=True)
        res = opt.solve(save_results=False)
        assert_optimal_termination(res)
        self.assertAlmostEqual(m.x.value, 0.25)
        self.assertAlmostEqual(m.y.value, -0.5)

        m.rel.pop_oa_points()
        m.rel.rebuild()
        res = opt.solve(save_results=False)
        assert_optimal_termination(res)
        self.assertAlmostEqual(m.x.value, 0)
        self.assertAlmostEqual(m.y.value, -1)