Skip to content

Commit

Permalink
Merge d535454 into f513185
Browse files Browse the repository at this point in the history
  • Loading branch information
dinever committed May 2, 2021
2 parents f513185 + d535454 commit 4e62e46
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -14,7 +14,7 @@ jobs:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
Expand Down
17 changes: 10 additions & 7 deletions .pylintrc
Expand Up @@ -52,13 +52,16 @@ confidence=
# --disable=W"

disable=arguments-differ,
missing-module-docstring,
duplicate-code,
abstract-method,
unused-argument,
too-many-instance-attributes,
too-many-public-methods,
too-many-ancestors
duplicate-code,
raise-missing-from,
missing-module-docstring,
invalid-name,
uplicate-code,
bstract-method,
nused-argument,
too-many-instance-attributes,
too-many-public-methods,
too-many-ancestors


[REPORTS]
Expand Down
2 changes: 1 addition & 1 deletion flipy/lp_objective.py
Expand Up @@ -33,7 +33,7 @@ def __init__(self, name: str = '', expression: Optional[Mapping[LpVariable, Nume
sense:
Whether to minimize or maximize the objective
"""
super(LpObjective, self).__init__(name, expression, constant)
super().__init__(name, expression, constant)
self._sense = None

self.sense = sense
Expand Down
41 changes: 20 additions & 21 deletions flipy/solvers/cbc_solver.py
Expand Up @@ -91,17 +91,17 @@ def solve(self, lp_problem: LpProblem) -> SolutionStatus:
flipy.SolutionStatus
The status of the solution
"""
temp_dir = tempfile.TemporaryDirectory()
lp_file_path = os.path.join(temp_dir.name, 'problem.lp')
solution_file_path = os.path.join(temp_dir.name, 'solution.sol')
with tempfile.TemporaryDirectory() as temp_dir:
lp_file_path = os.path.join(temp_dir.name, 'problem.lp')
solution_file_path = os.path.join(temp_dir.name, 'solution.sol')

with open(lp_file_path, 'w') as f:
lp_problem.write_lp(f)
with open(lp_file_path, 'w') as f:
lp_problem.write_lp(f)

self.call_cbc(f.name, solution_file_path)
self.call_cbc(f.name, solution_file_path)

if not os.path.exists(solution_file_path):
return SolutionStatus.NotSolved
if not os.path.exists(solution_file_path):
return SolutionStatus.NotSolved

return self.read_solution(solution_file_path, lp_problem)

Expand All @@ -120,19 +120,18 @@ def call_cbc(self, lp_file_path: str, solution_file_path: str):
solution_file_path:
Where to record the solution
"""
pipe = open(os.devnull, 'w')

args = [self.bin_path, lp_file_path]
if self.timeout:
args.extend(['sec', str(self.timeout)])
if self.mip_gap:
args.extend(['ratio', str(self.mip_gap)])
args.extend(['branch', 'printingOptions', 'all', 'solution', solution_file_path])

coin_proc = subprocess.Popen(args, stderr=pipe, stdout=pipe)
if coin_proc.wait() != 0:
raise SolverError(f"Error while trying to execute {self.bin_path}")
pipe.close()
with open(os.devnull, 'w') as pipe:

args = [self.bin_path, lp_file_path]
if self.timeout:
args.extend(['sec', str(self.timeout)])
if self.mip_gap:
args.extend(['ratio', str(self.mip_gap)])
args.extend(['branch', 'printingOptions', 'all', 'solution', solution_file_path])

with subprocess.Popen(args, stderr=pipe, stdout=pipe) as coin_proc:
if coin_proc.wait() != 0:
raise SolverError(f"Error while trying to execute {self.bin_path}")

@classmethod
def read_solution(cls, filename: str, lp_problem: LpProblem) -> SolutionStatus:
Expand Down
24 changes: 12 additions & 12 deletions flipy/solvers/gurobi_solver.py
Expand Up @@ -222,22 +222,22 @@ def solve(self, lp_problem: LpProblem) -> SolutionStatus:
flipy.SolutionStatus
The status of the solution
"""
temp_dir = tempfile.TemporaryDirectory()
problem_file_path = os.path.join(temp_dir.name, 'problem.lp')
solution_file_path = os.path.join(temp_dir.name, 'solution.sol')
with tempfile.TemporaryDirectory() as temp_dir:
problem_file_path = os.path.join(temp_dir.name, 'problem.lp')
solution_file_path = os.path.join(temp_dir.name, 'solution.sol')

with open(problem_file_path, 'w') as f:
lp_problem.write_lp(f)
with open(problem_file_path, 'w') as f:
lp_problem.write_lp(f)

model = gurobipy.read(problem_file_path)
model = gurobipy.read(problem_file_path)

model.setParam('MIPGap', self.mip_gap)
if self.timeout is not None:
model.setParam('TimeLimit', self.timeout)
model.setParam('MIPGap', self.mip_gap)
if self.timeout is not None:
model.setParam('TimeLimit', self.timeout)

model.optimize()
model.write(solution_file_path)
self.read_solution(solution_file_path, lp_problem)
model.optimize()
model.write(solution_file_path)
self.read_solution(solution_file_path, lp_problem)
return self.STATUS_MAPPING[model.Status]

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Expand Up @@ -2,8 +2,8 @@ coverage==5.0.3
pytest==5.3.5
pytest-cov==2.8.1
mock==2.0.0
pylint==2.4.4
pylint==2.8.2
coveralls==1.10.0
mkdocs_material==7.1.3
mkdocstrings==0.15.0
docstring-parser==0.7.3
docstring-parser==0.7.3

0 comments on commit 4e62e46

Please sign in to comment.