I have inherited a reasonably simple ortools-based optimizer (Python) with linear relationships that I need to non-linear-ize, and I have no idea how to do that.
The relevant part of my problem looks like this:
solver = pywraplp.Solver("B", pywraplp.Solver.GLOP_LINEAR_PROGRAMMING)
...
# charging a battery
## cap_prev: capacity before the current timeslot
## cap: ditto afterwards
## b_chg: charging power
## all are NumVar(0,some_hardware_limit)
solver.Add(cap_prev + 0.9 * b_chg - b_dis == cap)
The problem is that I need to replace the 0.9
with something that depends on the value of b_chg
. The Naïve solution looks like this:
solver.Add(cap_prev + b_chg_eff - b_dis == cap)
solver.Add(b_chg_eff == b_chg * (0.1+b_chg*0.8)).OnlyEnforceIf(b_chg<100)
solver.Add(b_chg_eff == b_chg * (0.9).OnlyEnforceIf(100<=b_chg<200)
solver.Add(b_chg_eff == b_chg * (0.9-(b_chg-200)*0.01).OnlyEnforceIf(200<=b_chg)
except that this is no longer linear, which kindof points to the assumption that I need a different solver.
Unfortunately I'm just starting off with OR in general, and ORtools in particular, and don't even know where to look next …
AddMultiplicationEquality()
and intermediate variables. $\endgroup$