Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if minizinc executable is installed #494

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Wout4 marked this conversation as resolved.
Show resolved Hide resolved
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():
Wout4 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading