VarIndex: Use tuples instead of lists

master
Alinson S. Xavier 5 years ago
parent d1bbe48662
commit d3c5371fa5

@ -6,7 +6,7 @@ import re
import sys
from io import StringIO
from random import randint
from typing import List, Any, Dict, Optional
from typing import List, Any, Dict, Optional, cast, Tuple, Union
from miplearn.instance import Instance
from miplearn.solvers import _RedirectOutput
@ -92,11 +92,14 @@ class GurobiSolver(InternalSolver):
m = re.search(r"([^[]*)\[(.*)]", var.varName)
if m is None:
name = var.varName
idx = [0]
idx = (0,)
else:
name = m.group(1)
parts = m.group(2).split(",")
idx = tuple(int(k) if k.isdecimal() else k for k in parts)
idx = cast(
Tuple[Union[str, int]],
tuple(int(k) if k.isdecimal() else str(k) for k in parts),
)
if len(idx) == 1:
idx = idx[0]
if name not in self._all_vars:

@ -2,11 +2,11 @@
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
# Released under the modified BSD license. See COPYING.md for more details.
from typing import Optional, Dict, Callable, Any, Union, List
from typing import Optional, Dict, Callable, Any, Union, Tuple
from mypy_extensions import TypedDict
VarIndex = Union[str, int, List[Union[str, int]]]
VarIndex = Union[str, int, Tuple[Union[str, int]]]
Solution = Dict[str, Dict[VarIndex, Optional[float]]]

Loading…
Cancel
Save