Beispiel #1
0
def run():
    model = Model("example_07_cost_sensitivity")

    x1 = model.create_variable("x1")
    x2 = model.create_variable("x2")
    x3 = model.create_variable("x3")

    model.add_constraint(6 * x1 + 5 * x2 + 8 * x3 <= 60)
    model.add_constraint(10 * x1 + 20 * x2 + 10 * x3 <= 150)
    model.add_constraint(x1 <= 8)

    model.maximize(5 * x1 + 4.5 * x2 + 6 * x3)

    solution = model.solve()

    analyser = Analyser()
    analysis_results = analyser.analyse(solution)
    analyser.interpret_results(solution, analysis_results, logging.info)

    objective_analysis_results = analysis_results[
        ObjectiveSensitivityAnalyser.name()]
    expected_bounds = [(4.636, 5.4), (4.167, 6.5), (float("-inf"), 6.571)]
    tolerance = 0.001
    for (i, bounds_pair) in enumerate(objective_analysis_results):
        assert math.isclose(
            bounds_pair[0], expected_bounds[i][0], abs_tol=tolerance
        ), f"left bound of the coefficient range seems to be incorrect, expected {expected_bounds[i][0]}, got {bounds_pair[0]}"
        assert math.isclose(
            bounds_pair[1], expected_bounds[i][1], abs_tol=tolerance
        ), f"right bound of the coefficient range seems to be incorrect, expected {expected_bounds[i][1]}, got {bounds_pair[1]}"

    logging.info(
        "Congratulations! This cost coefficients analysis look alright :)")
Beispiel #2
0
def run():
    primal = Model("zad 2")
    l = primal.create_variable("l")
    s = primal.create_variable("s")
    k = primal.create_variable("k")
    primal.add_constraint(8 * l + 6 * s + k <= 960)
    primal.add_constraint(8 * l + 4 * s + 3 * k <= 800)
    primal.add_constraint(4 * l + 3 * s + k <= 320)
    primal.maximize(60 * l + 30 * s + 20 * k)
    dual = primal.dual()
    primal_solution = primal.solve()
    print(dual)
    analyser = Analyser()
    analysis_results = analyser.analyse(primal_solution)
    analyser.interpret_results(primal_solution, analysis_results)
Beispiel #3
0
def run():
    primal = Model("zad 1")
    ss = primal.create_variable("ss")
    s = primal.create_variable("s")
    o = primal.create_variable("o")
    primal.add_constraint(2 * ss + 2 * s + 5 * o <= 40)
    primal.add_constraint(ss + 3 * s + 2 * o <= 30)
    primal.add_constraint(3 * ss + s + 3 * o <= 30)
    primal.maximize(32 * ss + 24 * s + 48 * o)
    dual = primal.dual()
    primal_solution = primal.solve()
    print(dual)
    analyser = Analyser()
    analysis_results = analyser.analyse(primal_solution)
    analyser.interpret_results(primal_solution, analysis_results)
from saport.simplex.analyser import Analyser
from saport.simplex.model import Model

# remember to print the dual model (just print()) and the analysis results (analyser.interpret_results(solution, analysis_results))
# in case of doubt refer to examples 06 and 07

primal = Model("Zad1")

ss = primal.create_variable("SS")
s = primal.create_variable("S")
o = primal.create_variable("O")

primal.add_constraint(2 * ss + 2 * s + 5 * o <= 40)
primal.add_constraint(ss + 3 * s + 2 * o <= 30)
primal.add_constraint(3 * ss + s + 3 * o <= 30)

primal.maximize(32 * ss + 24 * s + 48 * o)

dual = primal.dual()

print(dual)

solution = primal.solve()

analyser = Analyser()
analysis_results = analyser.analyse(solution)
analyser.interpret_results(solution, analysis_results)