bitten: update bitten.py
This commit is contained in:
parent
c66e25da24
commit
191bdec97d
1 changed files with 6 additions and 58 deletions
|
@ -133,84 +133,32 @@ def _flatten(it):
|
||||||
|
|
||||||
def _penalize_v2021_23(penalties, tol=1e-5, scale=1e10):
|
def _penalize_v2021_23(penalties, tol=1e-5, scale=1e10):
|
||||||
n_con = len(penalties)
|
n_con = len(penalties)
|
||||||
unmet = sum(p > 0.0 for p in penalties)
|
unmet = sum(p > tol for p in penalties)
|
||||||
growth = 4.0 ** (1.0 / n_con) # "ps"
|
growth = 4.0 ** (1.0 / n_con) # "ps"
|
||||||
penalty = 0.0
|
penalty = 0.0
|
||||||
for p in penalties:
|
for p in penalties:
|
||||||
p = max(p, 0.0)
|
p = p if p > tol else 0.0
|
||||||
squared = p * p
|
squared = p * p
|
||||||
penalty = growth * penalty + p + squared + p * squared
|
penalty = growth * penalty + p + squared + p * squared
|
||||||
return scale * (unmet + penalty)
|
return scale * (unmet + penalty)
|
||||||
|
|
||||||
|
|
||||||
def _penalize_v2022_11(penalties, tol=1e-5, scale=1e10):
|
|
||||||
n_con = len(penalties)
|
|
||||||
unmet = sum(p > 0.0 for p in penalties)
|
|
||||||
growth = 3.0 ** (1.0 / n_con) # "ps"
|
|
||||||
penalty = 0.0
|
|
||||||
for p in penalties:
|
|
||||||
p = max(p, 0.0)
|
|
||||||
penalty = growth * penalty + p + p * p * p
|
|
||||||
return scale * (unmet + penalty)
|
|
||||||
|
|
||||||
|
|
||||||
def _penalize_v2022_19(penalties, tol=1e-5, scale=1e10):
|
|
||||||
n_con = len(penalties)
|
|
||||||
growth = 3.0 ** (1.0 / n_con) # "ps"
|
|
||||||
increment = n_con**-0.5 # "pnsi"
|
|
||||||
penalty, nominal = 0.0, 0.0 # "pns", "pnsm"
|
|
||||||
for p in penalties:
|
|
||||||
p = max(p, 0.0)
|
|
||||||
penalty = growth * penalty + increment + p + p * p * p
|
|
||||||
nominal = growth * nominal + increment
|
|
||||||
return scale * (penalty - nominal + 1.0)
|
|
||||||
|
|
||||||
|
|
||||||
def _penalize_v2022_22(penalties, tol=1e-5, scale=1e10):
|
|
||||||
n_con = len(penalties)
|
|
||||||
growth = 3.0 ** (1.0 / n_con) # "ps"
|
|
||||||
increment = n_con**-0.5 # "pnsi"
|
|
||||||
coeff = increment**3.0 # "pnm"
|
|
||||||
penalty, nominal = 0.0, 0.0 # "pns", "pnsm"
|
|
||||||
for p in penalties:
|
|
||||||
p = coeff * max(p, 0.0)
|
|
||||||
squared = p * p
|
|
||||||
penalty = growth * penalty + increment + p + squared + p * squared
|
|
||||||
nominal = growth * nominal + increment
|
|
||||||
return scale * (penalty - nominal + 1.0)
|
|
||||||
|
|
||||||
|
|
||||||
def _penalize_v2022_25(penalties, tol=1e-5, scale=1e10):
|
def _penalize_v2022_25(penalties, tol=1e-5, scale=1e10):
|
||||||
n_con = len(penalties)
|
n_con = len(penalties)
|
||||||
growth = 3.0 ** (1.0 / n_con) # "ps"
|
growth = 3.0 ** (1.0 / n_con) # "ps"
|
||||||
increment = n_con**-0.5 # "pnsi"
|
increment = n_con**-0.5 # "pnsi"
|
||||||
penalty, nominal = 0.0, 0.0 # "pns", "pnsm"
|
penalty, nominal = 0.0, 0.0 # "pns", "pnsm"
|
||||||
for p in penalties:
|
for p in penalties:
|
||||||
p = max(p, 0.0)
|
p = p - tol if p > tol else 0.0
|
||||||
squared = p * p
|
squared = p * p
|
||||||
penalty = growth * penalty + increment + p + squared + p * squared
|
penalty = growth * penalty + increment + p + squared + p * squared
|
||||||
nominal = growth * nominal + increment
|
nominal = growth * nominal + increment
|
||||||
return scale * (penalty - nominal + 1.0)
|
return scale * (penalty - nominal + 1.0)
|
||||||
|
|
||||||
|
|
||||||
def _penalize_v2022_25_1(penalties, tol=1e-5, scale=1e10):
|
|
||||||
n_con = len(penalties)
|
|
||||||
growth = 3.0 ** (1.0 / n_con) # "ps"
|
|
||||||
increment = n_con**-0.5 # "pnsi"
|
|
||||||
penalty = 0.0 # "pns"
|
|
||||||
for p in penalties:
|
|
||||||
p = max(p, 0.0)
|
|
||||||
penalty = growth * penalty + increment + p + p * p
|
|
||||||
return scale * (1.0 + penalty + penalty * penalty)
|
|
||||||
|
|
||||||
|
|
||||||
penalizers = {
|
penalizers = {
|
||||||
1: _penalize_v2021_23,
|
+1: _penalize_v2021_23,
|
||||||
2: _penalize_v2022_11,
|
+5: _penalize_v2022_25,
|
||||||
3: _penalize_v2022_19,
|
|
||||||
4: _penalize_v2022_22,
|
|
||||||
5: _penalize_v2022_25,
|
|
||||||
6: _penalize_v2022_25_1,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -340,7 +288,7 @@ class Constrain(Objective):
|
||||||
|
|
||||||
def penalize(self, *x):
|
def penalize(self, *x):
|
||||||
penalties = _flatten(cons(*x) for cons in self.constraints)
|
penalties = _flatten(cons(*x) for cons in self.constraints)
|
||||||
if not any(p > 0.0 for p in penalties):
|
if not any(p > self.tol for p in penalties):
|
||||||
return 0.0
|
return 0.0
|
||||||
return self._penalize(penalties, tol=self.tol)
|
return self._penalize(penalties, tol=self.tol)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue