Example #1
0
 def test_solver_simple_od_leg_better(self):
     d = StringIO("1 1 1\n10 20 20")
     c = StringIO("1 1")
     dud = StringIO("0 1\n1 0\n1 1")
     problem = solver.create_problem_with_data(d, c, dud)
     this_solver = solver.Solver(None)
     result = this_solver.optimize_controls(problem)
     expected = DataFrame({'accepted_demand': [1.0, 1.0, 0.0]})
     self.assertTrue(array_equal(expected, result.accepted_demand))
     self.assertTrue(array_equal(30.0, result.expected_revenue))
Example #2
0
    def test_merge_controls(self):
        d = StringIO("1 0 2 4\n10 20 20 5")
        c = StringIO("1 1 1")
        dud = StringIO("0 1 0\n1 0 0\n1 1 0\n0 0 1")
        dp = StringIO("0 0 0 0\n1 2 2 4")
        problem = solver.create_problem_with_data(d, c, dud, dp)
        this_solver = solver.Solver(None)

        result1 = this_solver.optimize_controls_multi_period(
            problem, 0.1).expected_revenue
        sub_controls_list = []
        for p in problem.get_subproblems():
            sub_solver = solver.Solver(None)
            sub_controls_list.append(
                sub_solver.optimize_controls_multi_period(p, 0.1))

        result2 = merge_controls(sub_controls_list)

        eq_(result1, result2.expected_revenue)
Example #3
0
    def test_solver_single_ressource(self):
        d = StringIO("3 5 4 2 10\n10 5 4 2 1")
        c = StringIO("10")
        dud = StringIO("1\n1\n1\n1\n1")
        problem = solver.create_problem_with_data(d, c, dud)
        this_solver = solver.Solver(None)
        result = this_solver.optimize_controls(problem)

        expected = DataFrame({'accepted_demand': [3.0, 5.0, 2.0, 0.0, 0.0]})
        self.assertTrue(array_equal(expected, result.accepted_demand))
        self.assertTrue(array_equal(63.0, result.expected_revenue))
Example #4
0
    def test_problem_optimize_controls_multi_period_one_profile(self):
        d = StringIO("1 2 2 4\n10 20 20 5")
        c = self.three_id_capacity
        dud = StringIO("0 1 0\n1 0 0\n1 1 0\n0 0 1")
        dp = StringIO("1 2 2 4")
        problem = solver.create_problem_with_data(d, c, dud, dp)
        this_solver = solver.Solver(None)

        eq_(
            this_solver.optimize_controls_multi_period(problem,
                                                       0.1).expected_revenue,
            this_solver.optimize_controls(problem).expected_revenue)
Example #5
0
    def test_problem_get_subproblems(self):
        d = StringIO("1 2 2 4\n10 20 20 5")
        c = self.three_id_capacity
        dud = StringIO("0 1 0\n1 0 0\n1 1 0\n0 0 1")

        problem = solver.create_problem_with_data(d, c, dud)
        eq_(problem.get_subproblems().__len__(), 2)
        eq_(problem.get_subproblems()[1].demand_vector.ix[3], 4)
        eq_(problem.get_subproblems()[1].price_vector.ix[3], 5)
        this_solver = solver.Solver(None)

        eq_(
            this_solver.optimize_controls(problem).expected_revenue,
            this_solver.optimize_controls(
                problem.get_subproblems()[0]).expected_revenue + 5)