diff --git a/Pipfile b/Pipfile index c8ad4d2..6a2d91b 100644 --- a/Pipfile +++ b/Pipfile @@ -4,7 +4,7 @@ verify_ssl = true name = "pypi" [packages] -ortools = "~=9.0" +ortools = "9.1" windows-curses = {platform_system = "== 'Windows'"} [scripts] diff --git a/bonemarketsolver/objects/bone_market_model.py b/bonemarketsolver/objects/bone_market_model.py index a39a0b5..fa115f3 100644 --- a/bonemarketsolver/objects/bone_market_model.py +++ b/bonemarketsolver/objects/bone_market_model.py @@ -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) diff --git a/bonemarketsolver/solve.py b/bonemarketsolver/solve.py index 7293953..2be854b 100644 --- a/bonemarketsolver/solve.py +++ b/bonemarketsolver/solve.py @@ -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,7 +1201,8 @@ Exhaustion: {solver.Value(exhaustion):n}""" printer = SkeletonPrinter() solver = cp_model.CpSolver() - solver.parameters.num_search_workers = workers + if workers: + solver.parameters.num_search_workers = workers solver.parameters.max_time_in_seconds = time_limit # There's no window in verbose mode @@ -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()