ortools.sat.colab.flags

Collection of helpers to manage absl flags in colab.

  1# Copyright 2010-2024 Google LLC
  2# Licensed under the Apache License, Version 2.0 (the "License");
  3# you may not use this file except in compliance with the License.
  4# You may obtain a copy of the License at
  5#
  6#     http://www.apache.org/licenses/LICENSE-2.0
  7#
  8# Unless required by applicable law or agreed to in writing, software
  9# distributed under the License is distributed on an "AS IS" BASIS,
 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11# See the License for the specific language governing permissions and
 12# limitations under the License.
 13
 14"""Collection of helpers to manage absl flags in colab."""
 15
 16
 17class NotebookStringFlag:
 18    """Stub for absl flag to be used within a jupyter notebook."""
 19
 20    def __init__(self, name: str, value: str, doc: str):
 21        self.__name = name
 22        self.__value = value
 23        self.__doc__ = doc
 24
 25    @property
 26    def value(self) -> str:
 27        """Returns the value passed at creation."""
 28        return self.__value
 29
 30    @property
 31    def name(self) -> str:
 32        """Returns the name of the parameter."""
 33        return self.__name
 34
 35
 36def define_string(name: str, value: str, doc: str):
 37    return NotebookStringFlag(name, value, doc)
 38
 39
 40class NotebookIntFlag:
 41    """Stub for absl flag to be used within a jupyter notebook."""
 42
 43    def __init__(self, name: str, value: int, doc: str):
 44        self.__name = name
 45        self.__value = value
 46        self.__doc__ = doc
 47
 48    @property
 49    def value(self) -> int:
 50        """Returns the value passed at creation."""
 51        return self.__value
 52
 53    @property
 54    def name(self) -> str:
 55        """Returns the name of the parameter."""
 56        return self.__name
 57
 58
 59def define_integer(name: str, value: int, doc: str):
 60    return NotebookIntFlag(name, value, doc)
 61
 62
 63class NotebookFloatFlag:
 64    """Stub for absl flag to be used within a jupyter notebook."""
 65
 66    def __init__(self, name: str, value: float, doc: str):
 67        self.__name = name
 68        self.__value = value
 69        self.__doc__ = doc
 70
 71    @property
 72    def value(self) -> float:
 73        """Returns the value passed at creation."""
 74        return self.__value
 75
 76    @property
 77    def name(self) -> str:
 78        """Returns the name of the parameter."""
 79        return self.__name
 80
 81
 82def define_float(name: str, value: bool, doc: str):
 83    return NotebookFloatFlag(name, value, doc)
 84
 85
 86class NotebookBoolFlag:
 87    """Stub for absl flag to be used within a jupyter notebook."""
 88
 89    def __init__(self, name: str, value: bool, doc: str):
 90        self.__name = name
 91        self.__value = value
 92        self.__doc__ = doc
 93
 94    @property
 95    def value(self) -> bool:
 96        """Returns the value passed at creation."""
 97        return self.__value
 98
 99    @property
100    def name(self) -> str:
101        """Returns the name of the parameter."""
102        return self.__name
103
104
105def define_bool(name: str, value: bool, doc: str):
106    return NotebookBoolFlag(name, value, doc)
class NotebookStringFlag:
18class NotebookStringFlag:
19    """Stub for absl flag to be used within a jupyter notebook."""
20
21    def __init__(self, name: str, value: str, doc: str):
22        self.__name = name
23        self.__value = value
24        self.__doc__ = doc
25
26    @property
27    def value(self) -> str:
28        """Returns the value passed at creation."""
29        return self.__value
30
31    @property
32    def name(self) -> str:
33        """Returns the name of the parameter."""
34        return self.__name

Stub for absl flag to be used within a jupyter notebook.

NotebookStringFlag(name: str, value: str, doc: str)
21    def __init__(self, name: str, value: str, doc: str):
22        self.__name = name
23        self.__value = value
24        self.__doc__ = doc
value: str
26    @property
27    def value(self) -> str:
28        """Returns the value passed at creation."""
29        return self.__value

Returns the value passed at creation.

name: str
31    @property
32    def name(self) -> str:
33        """Returns the name of the parameter."""
34        return self.__name

Returns the name of the parameter.

def define_string(name: str, value: str, doc: str):
37def define_string(name: str, value: str, doc: str):
38    return NotebookStringFlag(name, value, doc)
class NotebookIntFlag:
41class NotebookIntFlag:
42    """Stub for absl flag to be used within a jupyter notebook."""
43
44    def __init__(self, name: str, value: int, doc: str):
45        self.__name = name
46        self.__value = value
47        self.__doc__ = doc
48
49    @property
50    def value(self) -> int:
51        """Returns the value passed at creation."""
52        return self.__value
53
54    @property
55    def name(self) -> str:
56        """Returns the name of the parameter."""
57        return self.__name

Stub for absl flag to be used within a jupyter notebook.

NotebookIntFlag(name: str, value: int, doc: str)
44    def __init__(self, name: str, value: int, doc: str):
45        self.__name = name
46        self.__value = value
47        self.__doc__ = doc
value: int
49    @property
50    def value(self) -> int:
51        """Returns the value passed at creation."""
52        return self.__value

Returns the value passed at creation.

name: str
54    @property
55    def name(self) -> str:
56        """Returns the name of the parameter."""
57        return self.__name

Returns the name of the parameter.

def define_integer(name: str, value: int, doc: str):
60def define_integer(name: str, value: int, doc: str):
61    return NotebookIntFlag(name, value, doc)
class NotebookFloatFlag:
64class NotebookFloatFlag:
65    """Stub for absl flag to be used within a jupyter notebook."""
66
67    def __init__(self, name: str, value: float, doc: str):
68        self.__name = name
69        self.__value = value
70        self.__doc__ = doc
71
72    @property
73    def value(self) -> float:
74        """Returns the value passed at creation."""
75        return self.__value
76
77    @property
78    def name(self) -> str:
79        """Returns the name of the parameter."""
80        return self.__name

Stub for absl flag to be used within a jupyter notebook.

NotebookFloatFlag(name: str, value: float, doc: str)
67    def __init__(self, name: str, value: float, doc: str):
68        self.__name = name
69        self.__value = value
70        self.__doc__ = doc
value: float
72    @property
73    def value(self) -> float:
74        """Returns the value passed at creation."""
75        return self.__value

Returns the value passed at creation.

name: str
77    @property
78    def name(self) -> str:
79        """Returns the name of the parameter."""
80        return self.__name

Returns the name of the parameter.

def define_float(name: str, value: bool, doc: str):
83def define_float(name: str, value: bool, doc: str):
84    return NotebookFloatFlag(name, value, doc)
class NotebookBoolFlag:
 87class NotebookBoolFlag:
 88    """Stub for absl flag to be used within a jupyter notebook."""
 89
 90    def __init__(self, name: str, value: bool, doc: str):
 91        self.__name = name
 92        self.__value = value
 93        self.__doc__ = doc
 94
 95    @property
 96    def value(self) -> bool:
 97        """Returns the value passed at creation."""
 98        return self.__value
 99
100    @property
101    def name(self) -> str:
102        """Returns the name of the parameter."""
103        return self.__name

Stub for absl flag to be used within a jupyter notebook.

NotebookBoolFlag(name: str, value: bool, doc: str)
90    def __init__(self, name: str, value: bool, doc: str):
91        self.__name = name
92        self.__value = value
93        self.__doc__ = doc
value: bool
95    @property
96    def value(self) -> bool:
97        """Returns the value passed at creation."""
98        return self.__value

Returns the value passed at creation.

name: str
100    @property
101    def name(self) -> str:
102        """Returns the name of the parameter."""
103        return self.__name

Returns the name of the parameter.

def define_bool(name: str, value: bool, doc: str):
106def define_bool(name: str, value: bool, doc: str):
107    return NotebookBoolFlag(name, value, doc)