Beispiel #1
0
 def test_get_gap_labels(self):
     l0, l1, l2 = get_gap_labels(1)
     assert l0 == 10
     assert l1 == "{gap:>10}"
     assert l2 == "{gap:>10.1f}"
     l0, l1, l2 = get_gap_labels(0.1)
     assert l0 == 10
     assert l1 == "{gap:>10}"
     assert l2 == "{gap:>10.2f}"
     l0, l1, l2 = get_gap_labels(0.01)
     assert l0 == 10
     assert l1 == "{gap:>10}"
     assert l2 == "{gap:>10.3f}"
     l0, l1, l2 = get_gap_labels(0.001)
     assert l0 == 10
     assert l1 == "{gap:>10}"
     assert l2 == "{gap:>10.4f}"
     l0, l1, l2 = get_gap_labels(0.0001)
     assert l0 == 10
     assert l1 == "{gap:>10}"
     assert l2 == "{gap:>10.5f}"
     l0, l1, l2 = get_gap_labels(0.00001)
     assert l0 == 11
     assert l1 == "{gap:>11}"
     assert l2 == "{gap:>11.6f}"
     l0, l1, l2 = get_gap_labels(0.000001, key='rgap')
     assert l0 == 12
     assert l1 == "{rgap:>12}"
     assert l2 == "{rgap:>12.7f}"
     l0, l1, l2 = get_gap_labels(0.0000001, key='agap', format='g')
     assert l0 == 13
     assert l1 == "{agap:>13}"
     assert l2 == "{agap:>13.8g}"
Beispiel #2
0
 def test_get_gap_labels(self):
     l0, l1, l2 = get_gap_labels(10)
     assert l0 == 10
     assert l1 == "{gap:>10}"
     assert l2 == "{gap:>10.2f}"
     l0, l1, l2 = get_gap_labels(1)
     assert l0 == 10
     assert l1 == "{gap:>10}"
     assert l2 == "{gap:>10.2f}"
     l0, l1, l2 = get_gap_labels(0.1)
     assert l0 == 10
     assert l1 == "{gap:>10}"
     assert l2 == "{gap:>10.3f}"
     l0, l1, l2 = get_gap_labels(0.01)
     assert l0 == 10
     assert l1 == "{gap:>10}"
     assert l2 == "{gap:>10.4f}"
     l0, l1, l2 = get_gap_labels(0.001)
     assert l0 == 10
     assert l1 == "{gap:>10}"
     assert l2 == "{gap:>10.5f}"
     l0, l1, l2 = get_gap_labels(0.0001)
     assert l0 == 11
     assert l1 == "{gap:>11}"
     assert l2 == "{gap:>11.6f}"
     l0, l1, l2 = get_gap_labels(0.00001)
     assert l0 == 12
     assert l1 == "{gap:>12}"
     assert l2 == "{gap:>12.7f}"
     l0, l1, l2 = get_gap_labels(0.000001, key="rgap")
     assert l0 == 13
     assert l1 == "{rgap:>13}"
     assert l2 == "{rgap:>13.8f}"
     l0, l1, l2 = get_gap_labels(0.0000001, key="agap", format="g")
     assert l0 == 14
     assert l1 == "{agap:>14}"
     assert l2 == "{agap:>14.9g}"
Beispiel #3
0
    def __init__(self, dispatcher, log, log_interval_seconds=1.0):
        assert log_interval_seconds >= 0
        self._dispatcher = dispatcher
        self._log_interval_seconds = log_interval_seconds
        self._log = log

        percent_relative_gap_tol = 1e-4
        if (
            self._dispatcher.converger.relative_gap is not None
        ) and self._dispatcher.converger.relative_gap != 0:
            percent_relative_gap_tol = 100.0 * self._dispatcher.converger.relative_gap
        rgap_str_length, rgap_label_str, rgap_number_str = get_gap_labels(
            percent_relative_gap_tol, key="rgap"
        )

        absolute_gap_tol = 1e-8
        if (
            self._dispatcher.converger.absolute_gap is not None
        ) and self._dispatcher.converger.absolute_gap != 0:
            absolute_gap_tol = self._dispatcher.converger.absolute_gap
        agap_str_length, agap_label_str, agap_number_str = get_gap_labels(
            absolute_gap_tol, key="agap", format="g"
        )

        assert rgap_str_length >= 10
        assert agap_str_length >= 10
        extra_space = (rgap_str_length - 10) + (agap_str_length - 10)
        extra_space_left = extra_space // 2
        extra_space_right = (extra_space // 2) + (extra_space % 2)
        self._lines = (
            "--------------------"
            "--------------------"
            "--------------------"
            "--------------------"
            "--------------------"
            "----------------"
        ) + ("-" * extra_space)
        self._initial_header_line = (
            self._lines + "\n"
            "         Nodes        |"
            + (" " * extra_space_left)
            + "                   Objective Bounds                    "
            + (" " * extra_space_right)
            + "|              Work              "
        )
        self._header_line = (
            " {explored:>9} {unexplored:>9}  |{objective:>15} "
            "{bound:>15} "
            + rgap_label_str
            + "  "
            + agap_label_str
            + " |{runtime:>9} {rate:>10} "
            "{imbalance:>9}  {idle:>5}"
        ).format(
            explored="Expl",
            unexplored="Unexpl",
            objective="Incumbent",
            bound="Bound",
            runtime="Time (s)",
            rgap="Rel. Gap",
            agap="Abs. Gap",
            rate="Nodes/Sec",
            imbalance="Imbalance",
            idle="Idle",
        )
        self._line_template = (
            "{tag:>1}{explored:>9d} {unexplored:>9d}  |{objective:>15.7g} "
            "{bound:>15.7g} "
            + rgap_number_str
            + "% "
            + agap_number_str
            + " |{runtime:>9.1f} {rate:>10.2f} "
            "{imbalance:>8.2f}% {idle:>6d}"
        )
        self._line_template_big_gap = (
            "{tag:>1}{explored:>9d} {unexplored:>9d}  |{objective:>15.7g} "
            "{bound:>15.7g} "
            + rgap_label_str
            + "% "
            + agap_number_str
            + " |{runtime:>9.1f} {rate:>10.2f} "
            "{imbalance:>8.2f}% {idle:>6d}"
        )

        self._last_print_time = float("-inf")
        served, explored, unexplored = self._dispatcher._get_node_counts()
        assert served == 0
        assert explored == 0
        assert unexplored == 0
        self._last_explored_nodes_count = 0
        self._last_rgap = None
        self._smoothing = 0.95
        self._avg_time_per_node = None
        self._print_count = 0
        self._new_objective = False
        self._report_new_objective = False