Skip to content

Commit

Permalink
check if minizinc executable is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
Wout4 committed Jun 17, 2024
1 parent 7e86304 commit 290d030
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions cpmpy/solvers/minizinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,36 @@ class CPM_minizinc(SolverInterface):
required_version = (2, 8, 2)
@staticmethod
def supported():
return CPM_minizinc.installed() and not CPM_minizinc.outdated()
return CPM_minizinc.installed() and CPM_minizinc.executable_installed() and not CPM_minizinc.outdated()

@staticmethod
def installed():
# try to import the package
try:
#check if MiniZinc Python is installed
import minizinc
return True
except ImportError as e:
return False

@staticmethod
def executable_installed():
# check if MiniZinc executable is installed
from minizinc import default_driver
if default_driver is None:
warnings.warn("MiniZinc Python is installed, but the MiniZinc executable is missing in path.")
return False
return True

@staticmethod
def outdated():
from minizinc import default_driver
if default_driver.parsed_version >= CPM_minizinc.required_version:
return False
else:
#outdated
# outdated
return True




@staticmethod
def solvernames():
"""
Expand Down Expand Up @@ -135,6 +142,8 @@ def __init__(self, cpm_model=None, subsolver=None):
"""
if not self.installed():
raise Exception("CPM_minizinc: Install the python package 'minizinc'")
if not self.executable_installed():
raise Exception("CPM_minizinc: Install the MiniZinc executable and make it available in path.")
elif self.outdated():
version = str(self.required_version[0])
for x in self.required_version[1:]:
Expand Down

0 comments on commit 290d030

Please sign in to comment.