Update OR-Tools to v9.1
This update, despite ostensibly being a minor version, includes breaking changes that must be accounted for. Overflow is much more strictly checked, so the magnitude of certain constants has been decreased. CP-SAT's default number of workers has been changed to reflect the default of this script. As such, the script no longer needs to change that parameter unless a specific number of workers has been specified. In light of the breaking changes, the OR-Tools version is now pinned at 9.1 instead of being permitted to use future minor versions.
This commit is contained in:
parent
5a3f4f6454
commit
110f524f62
2
Pipfile
2
Pipfile
|
@ -4,7 +4,7 @@ verify_ssl = true
|
|||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
ortools = "~=9.0"
|
||||
ortools = "9.1"
|
||||
windows-curses = {platform_system = "== 'Windows'"}
|
||||
|
||||
[scripts]
|
||||
|
|
|
@ -28,7 +28,7 @@ Each parameter is interpreted as a BoundedLinearExpression, and a layer of indir
|
|||
Each parameter is interpreted as a BoundedLinearExpression, and a layer of indirection is applied such that each Constraint in the returned tuple can accept an enforcement literal."""
|
||||
intermediate_target, target_constraint = self.NewIntermediateIntVar(target, f'{repr(target)} == {repr(num)} // {repr(denom)}: target')
|
||||
intermediate_num, num_constraint = self.NewIntermediateIntVar(num, f'{repr(target)} == {repr(num)} // {repr(denom)}: num', lb = 0)
|
||||
intermediate_denom, denom_constraint = self.NewIntermediateIntVar(denom, f'{repr(target)} == {repr(num)} // {repr(denom)}: denom', lb = 0)
|
||||
intermediate_denom, denom_constraint = self.NewIntermediateIntVar(denom, f'{repr(target)} == {repr(num)} // {repr(denom)}: denom', lb = 1)
|
||||
|
||||
super().AddDivisionEquality(intermediate_target, intermediate_num, intermediate_denom)
|
||||
return (target_constraint, num_constraint, denom_constraint)
|
||||
|
@ -41,7 +41,7 @@ Each parameter is interpreted as a BoundedLinearExpression, and a layer of indir
|
|||
`multiple` defaults to the same value as `denom` if unspecified."""
|
||||
quotient = self.NewIntVar(f'{repr(target)} == ({repr(num)} // {repr(denom)}) * {repr(multiple)}: quotient')
|
||||
intermediate_num, num_constraint = self.NewIntermediateIntVar(num, f'{repr(target)} == ({repr(num)} // {repr(denom)}) * {repr(multiple)}: num', lb = 0)
|
||||
intermediate_denom, denom_constraint = self.NewIntermediateIntVar(denom, f'{repr(target)} == ({repr(num)} // {repr(denom)}) * {repr(multiple)}: denom', lb = 0)
|
||||
intermediate_denom, denom_constraint = self.NewIntermediateIntVar(denom, f'{repr(target)} == ({repr(num)} // {repr(denom)}) * {repr(multiple)}: denom', lb = 1)
|
||||
intermediate_target, target_constraint = self.NewIntermediateIntVar(target, f'{repr(target)} == ({repr(num)} // {repr(denom)}) * {repr(multiple)}: target')
|
||||
if multiple:
|
||||
intermediate_multiple, multiple_constraint = self.NewIntermediateIntVar(multiple, f'{repr(target)} == ({repr(num)} // {repr(denom)}) * {repr(multiple)}: multiple')
|
||||
|
@ -110,7 +110,7 @@ Each parameter is interpreted as a BoundedLinearExpression, and a layer of indir
|
|||
self.AddLinearExpressionInDomain(linear_exp, domain.Complement()).OnlyEnforceIf(intermediate.Not())
|
||||
return intermediate
|
||||
|
||||
def NewIntermediateIntVar(self, linear_exp, name, *, lb = cp_model.INT_MIN//8, ub = cp_model.INT_MAX//8):
|
||||
def NewIntermediateIntVar(self, linear_exp, name, *, lb = cp_model.INT32_MIN, ub = cp_model.INT32_MAX):
|
||||
"""Creates an integer variable equivalent to the given expression and returns a tuple consisting of the variable and constraint for use with enforcement literals."""
|
||||
|
||||
intermediate = super().NewIntVar(lb, ub, name)
|
||||
|
|
|
@ -4,7 +4,6 @@ __all__ = ['Adjustment', 'Appendage', 'Buyer', 'Declaration', 'DiplomatFascinati
|
|||
__author__ = "Jeremy Saklad"
|
||||
|
||||
from functools import partialmethod
|
||||
from os import cpu_count
|
||||
|
||||
from ortools.sat.python import cp_model
|
||||
|
||||
|
@ -22,7 +21,7 @@ from .data.torsos import Torso
|
|||
from .objects.bone_market_model import BoneMarketModel
|
||||
|
||||
# This multiplier is applied to the profit margin to avoid losing precision due to rounding.
|
||||
PROFIT_MARGIN_MULTIPLIER = 10000000
|
||||
PROFIT_MARGIN_MULTIPLIER = 10000
|
||||
|
||||
# This is the highest number of attribute to calculate fractional exponents for.
|
||||
MAXIMUM_ATTRIBUTE = 100
|
||||
|
@ -31,7 +30,7 @@ MAXIMUM_ATTRIBUTE = 100
|
|||
DIFFICULTY_SCALER = 0.6
|
||||
|
||||
|
||||
def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = None, occasional_buyer = None, diplomat_fascination = None, desired_buyers = [], maximum_cost = cp_model.INT32_MAX, maximum_exhaustion = cp_model.INT32_MAX, time_limit = float('inf'), workers = cpu_count(), blacklist = [], stdscr = None):
|
||||
def Solve(shadowy_level, bone_market_fluctuations = None, zoological_mania = None, occasional_buyer = None, diplomat_fascination = None, desired_buyers = [], maximum_cost = cp_model.INT32_MAX, maximum_exhaustion = cp_model.INT32_MAX, time_limit = float('inf'), workers = None, blacklist = [], stdscr = None):
|
||||
model = BoneMarketModel()
|
||||
|
||||
actions = {}
|
||||
|
@ -1202,6 +1201,7 @@ Exhaustion: {solver.Value(exhaustion):n}"""
|
|||
printer = SkeletonPrinter()
|
||||
|
||||
solver = cp_model.CpSolver()
|
||||
if workers:
|
||||
solver.parameters.num_search_workers = workers
|
||||
solver.parameters.max_time_in_seconds = time_limit
|
||||
|
||||
|
@ -1210,7 +1210,7 @@ Exhaustion: {solver.Value(exhaustion):n}"""
|
|||
solver.parameters.log_search_progress = True
|
||||
solver.Solve(model)
|
||||
else:
|
||||
solver.SolveWithSolutionCallback(model, printer)
|
||||
solver.Solve(model, printer)
|
||||
|
||||
status = solver.StatusName()
|
||||
|
||||
|
|
Loading…
Reference in New Issue