示例#1
0
    def test_raise_due_to_invalid_priority(self):
        self.mock_model.priority = self.suffix_cls(direction=Suffix.EXPORT, datatype=Suffix.INT)
        self._set_suffix_value(self.mock_model.priority, self.mock_model.x, -1)
        with self.assertRaises(ValueError):
            CPLEXSHELL._write_priorities_file(self.mock_cplex_shell, self.mock_model)

        self._set_suffix_value(self.mock_model.priority, self.mock_model.x, 1.1)
        with self.assertRaises(ValueError):
            CPLEXSHELL._write_priorities_file(self.mock_cplex_shell, self.mock_model)
示例#2
0
    def test_write_priority_to_priorities_file(self):
        self.mock_model.priority = self.suffix_cls(direction=Suffix.EXPORT, datatype=Suffix.INT)
        priority_val = 10
        self._set_suffix_value(self.mock_model.priority, self.mock_model.x, priority_val)

        CPLEXSHELL._write_priorities_file(self.mock_cplex_shell, self.mock_model)
        priorities_file = self.get_priorities_file_as_string(self.mock_cplex_shell)

        self.assertEqual(
            priorities_file,
            "* ENCODING=ISO-8859-1\n"
            "NAME             Priority Order\n"
            "  x1 10\n"
            "ENDATA\n"
        )
示例#3
0
    def test_log_file_shows_n_solutions_found_when_single(self):
        log_file_text = """
Solution pool: 1 solution saved.
 """
        with open(self.solver._log_file, "w") as f:
            f.write(log_file_text)

        results = CPLEXSHELL.process_logfile(self.solver)
        self.assertEqual(results.solver.n_solutions_found, 1)
示例#4
0
    def test_log_file_shows_warm_start_failure(self):
        log_file_text = """
Warning:  No solution found from 1 MIP starts.
"""
        with open(self.solver._log_file, "w") as f:
            f.write(log_file_text)

        results = CPLEXSHELL.process_logfile(self.solver)
        self.assertEqual(results.solver.mip_start_failed, True)
示例#5
0
    def test_log_file_shows_number_of_binary_variables_when_integer_variables_are_present(
            self):
        log_file_text = """
Variables : 7 [Nneg: 1, Binary: 4, General Integer: 2]
 """
        with open(self.solver._log_file, "w") as f:
            f.write(log_file_text)

        results = CPLEXSHELL.process_logfile(self.solver)
        self.assertEqual(results.problem.number_of_binary_variables, 4)
示例#6
0
    def test_log_file_shows_warm_start_objective_value(self):
        log_file_text = """
1 of 1 MIP starts provided solutions.
MIP start 'm1' defined initial solution with objective 25210.5363.
"""
        with open(self.solver._log_file, "w") as f:
            f.write(log_file_text)

        results = CPLEXSHELL.process_logfile(self.solver)
        self.assertEqual(results.solver.warm_start_objective_value, 25210.5363)
示例#7
0
    def test_log_file_shows_number_of_continuous_variables(self):
        log_file_text = """
Objective sense      : Minimize
Variables            :     506  [Nneg: 206,  Binary: 300]
Objective nonzeros   :      32
 """
        with open(self.solver._log_file, "w") as f:
            f.write(log_file_text)

        results = CPLEXSHELL.process_logfile(self.solver)
        self.assertEqual(results.problem.number_of_continuous_variables, 206)
示例#8
0
    def test_log_file_shows_tree_processing_time_when_sequential(self):
        log_file_text = """
Presolve time = 0.14 sec. (181.11 ticks)

Root node processing (before b&c):
  Real time             =    123.45 sec. (211.39 ticks)
Sequential b&c:
  Real time             =    67.89 sec. (56.98 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    191.34 sec. (268.37 ticks)
 """
        with open(self.solver._log_file, "w") as f:
            f.write(log_file_text)

        results = CPLEXSHELL.process_logfile(self.solver)
        self.assertEqual(results.solver.tree_processing_time, 67.89)
示例#9
0
    def test_log_file_shows_max_deterministic_time_limit_exceeded_with_feasible_solution(
            self):
        log_file_text = """
MIP - Deterministic time limit exceeded, integer feasible:  Objective =  0.0000000000e+00
Current MIP best bound =  0.0000000000e+00 (gap = 10.0, 10.00%)
Solution time =   10.00 sec.  Iterations = 10000  Nodes = 1000 (1)
Deterministic time = 100.00 ticks  (10.00 ticks/sec)

CPLEX> Incumbent solution written to file '/var/folders/_x/xxxx/T/tmpxxx.cplex.sol'.
CPLEX>"""
        with open(self.solver._log_file, "w") as f:
            f.write(log_file_text)

        results = CPLEXSHELL.process_logfile(self.solver)
        self.assertEqual(results.solver.status, SolverStatus.ok)
        self.assertEqual(results.solver.termination_condition,
                         TerminationCondition.maxTimeLimit)
        self.assertEqual(results.solver.deterministic_time, 100.00)
示例#10
0
    def test_log_file_shows_infeasible(self):
        log_file_text = """
MIP - Integer infeasible.
Current MIP best bound =  0.0000000000e+00 (gap is infinite)
Solution time =    0.00 sec.  Iterations = 0  Nodes = 0
Deterministic time = 0.00 ticks  (0.20 ticks/sec)

CPLEX> CPLEX Error  1217: No solution exists.
No file written.
CPLEX>"""
        with open(self.solver._log_file, "w") as f:
            f.write(log_file_text)

        results = CPLEXSHELL.process_logfile(self.solver)
        self.assertEqual(results.solver.status, SolverStatus.warning)
        self.assertEqual(results.solver.termination_condition,
                         TerminationCondition.infeasible)
        self.assertEqual(results.solver.termination_message,
                         "MIP - Integer infeasible.")
        self.assertEqual(results.solver.return_code, 1217)
示例#11
0
    def test_log_file_shows_presolve_infeasible(self):
        log_file_text = """
Infeasibility row 'c_e_x18_':  0  = -1.
Presolve time = 0.00 sec. (0.00 ticks)
Presolve - Infeasible.
Solution time =    0.00 sec.
Deterministic time = 0.00 ticks  (0.61 ticks/sec)
CPLEX> CPLEX Error  1217: No solution exists.
No file written.
CPLEX>"""

        with open(self.solver._log_file, "w") as f:
            f.write(log_file_text)

        results = CPLEXSHELL.process_logfile(self.solver)
        self.assertEqual(results.solver.status, SolverStatus.warning)
        self.assertEqual(results.solver.termination_condition,
                         TerminationCondition.infeasible)
        self.assertEqual(results.solver.termination_message,
                         "Presolve - Infeasible.")
        self.assertEqual(results.solver.return_code, 1217)
示例#12
0
 def test_write_without_priority_suffix(self):
     with self.assertRaises(ValueError):
         CPLEXSHELL._write_priorities_file(self.mock_cplex_shell,
                                           self.mock_model)