コード例 #1
0
 def test_substitution_issue905(self):
     x = Variable("x")
     y = Variable("y")
     m = Model(x, [x >= y], {"y": 1})
     bm = Model(m.cost, Bounded(m))
     sol = bm.solve(verbosity=0)
     self.assertAlmostEqual(sol["cost"], 1.0)
     bm = Model(m.cost, Bounded(m, lower=1e-10))
     sol = bm.solve(verbosity=0)
     self.assertAlmostEqual(sol["cost"], 1.0)
     bm = Model(m.cost, Bounded(m, upper=1e10))
     sol = bm.solve(verbosity=0)
     self.assertAlmostEqual(sol["cost"], 1.0)
コード例 #2
0
ファイル: t_model.py プロジェクト: khosravipasha/gpkit
    def test_sp_bounded(self):
        x = Variable("x")
        y = Variable("y")

        with SignomialsEnabled():
            m = Model(x, [x + y >= 1, y <= 0.1])  # solves
        cost = m.localsolve(verbosity=0, solver=self.solver)["cost"]
        self.assertAlmostEqual(cost, 0.9, self.ndig)

        with SignomialsEnabled():
            m = Model(x, [x + y >= 1])  # dual infeasible
        with self.assertRaises(UnboundedGP):
            m.localsolve(verbosity=0, solver=self.solver)
        gp = m.sp(checkbounds=False).gp()
        self.assertRaises(DualInfeasible,
                          gp.solve,
                          solver=self.solver,
                          verbosity=0)

        with SignomialsEnabled():
            m = Model(x, Bounded([x + y >= 1], verbosity=0))
        sol = m.localsolve(verbosity=0, solver=self.solver)
        boundedness = sol["boundedness"]
        # depends on solver, platform, whims of the numerical deities
        if "value near lower bound" in boundedness:  # pragma: no cover
            self.assertIn(x.key, boundedness["value near lower bound"])
        else:  # pragma: no cover
            self.assertIn(y.key, boundedness["value near upper bound"])
コード例 #3
0
ファイル: t_model.py プロジェクト: beldonl/gpkit
    def test_sp_bounded(self):
        x = Variable("x")
        y = Variable("y")

        with SignomialsEnabled():
            m = Model(x, [x + y >= 1, y <= 0.1])  # solves
        cost = m.localsolve(verbosity=0, solver=self.solver)["cost"]
        self.assertAlmostEqual(cost, 0.9, self.ndig)

        with SignomialsEnabled():
            m = Model(x, [x + y >= 1])  # dual infeasible
        with self.assertRaises(UnboundedGP):
            m.localsolve(verbosity=0, solver=self.solver)
        gp = m.sp(allow_missingbounds=True).gp(allow_missingbounds=True)
        self.assertRaises(DualInfeasible,
                          gp.solve,
                          solver=self.solver,
                          verbosity=0)

        with SignomialsEnabled():
            m = Model(x, Bounded([x + y >= 1], verbosity=0))
        sol = m.localsolve(verbosity=0, solver=self.solver)
        boundedness = sol["boundedness"]
        if "value near lower bound" in boundedness:
            self.assertIn(x.key, boundedness["value near lower bound"])
        if "value near upper bound" in boundedness:
            self.assertIn(y.key, boundedness["value near upper bound"])
コード例 #4
0
 def test_unbounded_debugging(self):
     "Test nearly-dual-feasible problems"
     x = Variable("x")
     y = Variable("y")
     m = Model(x * y, [x * y**1.01 >= 100])
     with self.assertRaises((RuntimeWarning, ValueError)):
         m.solve(self.solver, verbosity=0)
     # test one-sided bound
     m = Model(x * y, Bounded(m, verbosity=0, lower=0.001))
     sol = m.solve(self.solver, verbosity=0)
     bounds = sol["boundedness"]
     self.assertEqual(bounds["sensitive to lower bound"], [x.key])
     # end test one-sided bound
     m = Model(x * y, Bounded(m, verbosity=0))
     sol = m.solve(self.solver, verbosity=0)
     bounds = sol["boundedness"]
     if "sensitive to upper bound" in bounds:
         self.assertEqual(bounds["sensitive to upper bound"], [y.key])
     if "sensitive to lower bound" in bounds:
         self.assertEqual(bounds["sensitive to lower bound"], [x.key])
コード例 #5
0
ファイル: t_model.py プロジェクト: beldonl/gpkit
 def test_unbounded_debugging(self):
     "Test nearly-dual-feasible problems"
     x = Variable("x")
     y = Variable("y")
     m = Model(x * y, [x * y**1.01 >= 100])
     with self.assertRaises((DualInfeasible, UnknownInfeasible)):
         m.solve(self.solver, verbosity=0)
     # test one-sided bound
     m = Model(x * y, Bounded(m, verbosity=0, lower=0.001))
     sol = m.solve(self.solver, verbosity=0)
     bounds = sol["boundedness"]
     self.assertEqual(bounds["sensitive to lower bound"], set([x.key]))
     # end test one-sided bound
     m = Model(x * y, Bounded(m, verbosity=0))
     sol = m.solve(self.solver, verbosity=0)
     bounds = sol["boundedness"]
     if "sensitive to upper bound" in bounds:
         self.assertIn(y.key, bounds["sensitive to upper bound"])
     if "sensitive to lower bound" in bounds:
         self.assertIn(x.key, bounds["sensitive to lower bound"])
コード例 #6
0
ファイル: t_model.py プロジェクト: gitter-badger/gpkit
 def test_unbounded_debugging(self):
     "Test nearly-dual-feasible problems"
     from gpkit.constraints.bounded import Bounded
     x = Variable("x")
     y = Variable("y")
     m = Model(x*y, [x*y**1.000001 >= 100])
     with self.assertRaises((RuntimeWarning, ValueError)):
         m.solve(self.solver, verbosity=0)
     m = Model(x*y, Bounded(m, verbosity=0))
     sol = m.solve(self.solver, verbosity=0)
     bounds = sol["boundedness"]
     self.assertEqual(bounds["sensitive to upper bound"], [y.key])
     self.assertEqual(bounds["sensitive to lower bound"], [x.key])
コード例 #7
0
 def test_unbounded_debugging(self):
     "Test nearly-dual-feasible problems"
     x = Variable("x")
     y = Variable("y")
     m = Model(x * y, [x * y**1.01 >= 100])
     with self.assertRaises((DualInfeasible, UnknownInfeasible)):
         m.solve(self.solver, verbosity=0)
     # test one-sided bound
     m = Model(x * y, Bounded(m, lower=0.001))
     sol = m.solve(self.solver, verbosity=0)
     bounds = sol["boundedness"]
     self.assertEqual(bounds["sensitive to lower bound of 0.001"],
                      set([x.key]))
     # end test one-sided bound
     m = Model(x * y, [x * y**1.01 >= 100])
     m = Model(x * y, Bounded(m))
     sol = m.solve(self.solver, verbosity=0)
     bounds = sol["boundedness"]
     # depends on solver, platform, whims of the numerical deities
     if "sensitive to upper bound of 1e+30" in bounds:  # pragma: no cover
         self.assertIn(y.key, bounds["sensitive to upper bound of 1e+30"])
     else:  # pragma: no cover
         self.assertIn(x.key, bounds["sensitive to lower bound of 1e-30"])
コード例 #8
0
    def test_sp_bounded(self):
        x = Variable("x")
        y = Variable("y")

        with SignomialsEnabled():
            m = Model(x, [x + y >= 1, y <= 0.1])  # solves
        cost = m.localsolve(verbosity=0)["cost"]
        self.assertAlmostEqual(cost, 0.9, self.ndig)

        with SignomialsEnabled():
            m = Model(x, [x + y >= 1])  # dual infeasible
        with self.assertRaises((RuntimeWarning, ValueError)):
            m.localsolve(verbosity=0)

        with SignomialsEnabled():
            m = Model(x, Bounded([x + y >= 1], verbosity=0))
        sol = m.localsolve(verbosity=0)
        if "value near lower bound" in sol["boundedness"]:
            self.assertIn(x, sol["boundedness"]["value near lower bound"])
        if "value near upper bound" in sol["boundedness"]:
            self.assertIn(y, sol["boundedness"]["value near upper bound"])
コード例 #9
0
def optimize_aircraft(m, substitutions, fixedBPR=False, pRatOpt=True, x0 = None):
    """
    Optimizes an aircraft of a given configuration
    :param m: aircraft model with objective and configuration
    :param fixedBPR: boolean specifying whether or not BPR is fixed (depends on config)
    :param pRatOpt: boolean specifying whether or not pressure ratio is optimized (depends on config)
    :return: solution of aircraft model
    """

    if fixedBPR:
        substitutions.update({
            '\\alpha_{max}': 6.97, #8.62,
        })

    if pRatOpt:
        del substitutions['\pi_{f_D}']
        del substitutions['\pi_{lc_D}']
        del substitutions['\pi_{hc_D}']

    m.substitutions.update(substitutions)
    m = Model(m.cost, Bounded(m), m.substitutions)
    sol = m.localsolve(verbosity=2, iteration_limit=200, reltol=0.01)
    return sol
コード例 #10
0
def relaxed_constants(model, include_only=None, exclude=None):
    """
    Method to precondition an SP so it solves with a relaxed constants
        algorithim

    ARGUMENTS
    ---------
    model: the model to solve with relaxed constants

    RETURNS
    -------
    feas: the input model but with relaxed constants and a new objective
    """

    if model.substitutions:
        constsrelaxed = ConstantsRelaxed(Bounded(model))
        feas = Model(constsrelaxed.relaxvars.prod()**20 * model.cost,
                     constsrelaxed)
        # NOTE: It hasn't yet been seen but might be possible that
        #       the model.cost component above could cause infeasibility
    else:
        feas = Model(model.cost, model)

    return feas
コード例 #11
0
"Demonstrate a trivial unbounded variable"
from gpkit import Variable, Model
from gpkit.constraints.bounded import Bounded

x = Variable("x")

constraints = [x >= 1]

m = Model(1/x, constraints)  # MOSEK returns DUAL_INFEAS_CER on .solve()
m = Model(1/x, Bounded(constraints))
# by default, prints bounds warning during solve
sol = m.solve(verbosity=0)
print(sol.summary())
# but they can also be accessed from the solution:
assert (sol["boundedness"]["value near upper bound of 1e+30"]
        == sol["boundedness"]["sensitive to upper bound of 1e+30"])