mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
VarIndex: Use tuples instead of lists
This commit is contained in:
@@ -6,7 +6,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from random import randint
|
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.instance import Instance
|
||||||
from miplearn.solvers import _RedirectOutput
|
from miplearn.solvers import _RedirectOutput
|
||||||
@@ -92,11 +92,14 @@ class GurobiSolver(InternalSolver):
|
|||||||
m = re.search(r"([^[]*)\[(.*)]", var.varName)
|
m = re.search(r"([^[]*)\[(.*)]", var.varName)
|
||||||
if m is None:
|
if m is None:
|
||||||
name = var.varName
|
name = var.varName
|
||||||
idx = [0]
|
idx = (0,)
|
||||||
else:
|
else:
|
||||||
name = m.group(1)
|
name = m.group(1)
|
||||||
parts = m.group(2).split(",")
|
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:
|
if len(idx) == 1:
|
||||||
idx = idx[0]
|
idx = idx[0]
|
||||||
if name not in self._all_vars:
|
if name not in self._all_vars:
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# 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
|
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]]]
|
Solution = Dict[str, Dict[VarIndex, Optional[float]]]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user