I'm especially interested in the standard CPLEX Python interface. An obvious approach is to use a try: ... except: ...
block and using more than 1000 variables in a program. But I'm hoping for a cleaner approach, more direct approach.

- 539
- 1
- 5
- 10
-
are the version numbers the same between editions? – Jason Jan 25 '18 at 16:00
1 Answers
As of the latest version of CPLEX (currently 12.8), there is no method that will tell you whether you're using the community edition (CE) or not.
As you have suggested, you can use a try-except block to catch the error you would get if you're trying to solve a model that is too big for CE. The error code is CPXERR_RESTRICTED_VERSION. However, it sounds like you are trying to proactively figure out if a user is running CE. Instead, you should lazily check for it. That is, don't create a method that creates a dummy model with more than 1000 variables just to find out ahead of time if the user has CE. Just deal with the exception if it arises. This lines up with the EAFP principle in Python. For example, you can do something like the following:
import cplex
from cplex.exceptions import CplexSolverError, error_codes
# Build the model
model = cplex.Cplex()
# Add variables, constraints, etc.
try:
model.solve()
except CplexSolverError as cse:
# Check whether the model exceeds problem size limits (i.e.,
# the user has Community Edition). The following demonstrates
# how to handle a specific error code.
if cse.args[2] == error_codes.CPXERR_RESTRICTED_VERSION:
print("The current problem is too large for your version of "
"CPLEX. Reduce the size of the problem.")
else:
raise
Another idea, would be to count the variables before solving and issue a warning. Something like:
if model.variables.get_num() > 1000:
print("Warning: this model may be too large for your version of CPLEX.")

- 4,447
- 2
- 22
- 31