Skip to content

Commit

Permalink
Comments, and reverting funky use of l_norm in exponential. (checked …
Browse files Browse the repository at this point in the history
…with SimPleAC_table from robustSPpaper).
  • Loading branch information
1ozturkbe committed Jun 25, 2019
1 parent 10a48d1 commit b4ef96c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions robust/robust.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def set(self, option_name, value):


class RobustModel:
"""
RobustModel extends gpkit.Model through the robust counterpart.
It uses the nominal solution of the GP or SP to
"""
def __init__(self, model, type_of_uncertainty_set, **options):
self.nominal_model = model
self.substitutions = model.substitutions
Expand Down Expand Up @@ -113,9 +117,8 @@ def __init__(self, model, type_of_uncertainty_set, **options):
else:
p = cs.as_posyslt1()[0]
if len(p.exps) == 1:
robust_monomial, l_norm = self.robustify_monomial(p)
a = Variable()
self.ready_gp_constraints += [robust_monomial <= a**(1/l_norm), a <= 1]
robust_monomial = self.robustify_monomial(p)
self.ready_gp_constraints += [robust_monomial <= 1]
else:
self.to_linearize_gp_posynomials += [p]
del safe_model_constraints
Expand Down Expand Up @@ -262,9 +265,8 @@ def classify_gp_constraints(self, gp_posynomials, offset=0):
large_gp_posynomials = []
for i, p in enumerate(data_gp_posynomials):
if len(p.exps) == 1:
robust_monomial, l_norm = self.robustify_monomial(p)
a = Variable()
ready_gp_constraints += [robust_monomial <= a**(1/l_norm), a <= 1]
robust_monomial = self.robustify_monomial(p)
ready_gp_constraints += [robust_monomial <= 1]
elif len(p.exps) == 2 and self.setting.get('linearizeTwoTerm'):
to_linearize_gp_posynomials += [p]
else:
Expand Down Expand Up @@ -303,16 +305,15 @@ def robustify_monomial(self, monomial):
l_norm = np.sqrt(l_norm)
g = self.setting.get('gamma')
# Fifth order Taylor approx of the e**gamma, so that gamma can be a variable
robust_monomial = monomial**(1/l_norm) * (1.+g+1./2.*g**2+1./6.*g**3+1./24.*g**4+1./120.*g**5)
return robust_monomial, l_norm
robust_monomial = monomial * (1.+g+1./2.*g**2+1./6.*g**3+1./24.*g**4+1./120.*g**5)**l_norm
return robust_monomial

def robustify_set_of_monomials(self, set_of_monomials, feasible=False):
robust_set_of_monomial_constraints = []
slackvar = Variable()
for monomial in set_of_monomials:
robust_monomial, l_norm = self.robustify_monomial(monomial)
a = Variable()
robust_set_of_monomial_constraints += [robust_monomial <= a**(1/l_norm), a <= slackvar ** feasible]
robust_monomial = self.robustify_monomial(monomial)
robust_set_of_monomial_constraints += [robust_monomial <= slackvar ** feasible]
robust_set_of_monomial_constraints += [slackvar >= 1, slackvar <= 1000]
return robust_set_of_monomial_constraints, slackvar

Expand Down Expand Up @@ -342,15 +343,15 @@ def calculate_value_of_two_term_approximated_posynomial(self, two_term_approxima
subs_monomials = []
for j in xrange(len(monomials)):
# st3 = time()
robust_monomial, l_norm = self.robustify_monomial(monomials[j])
robust_monomial = self.robustify_monomial(monomials[j])
monomials[j] = robust_monomial.sub(solution['variables'])
# print "subs for a monomial is taking too much time", time()-st3
subs_monomials.append(monomials[j].cs[0])
values.append(max(subs_monomials))
if number_of_two_terms % 2 != 0:
monomial = Monomial(two_term_approximation.p.exps[permutation[len(permutation) - 1]],
two_term_approximation.p.cs[permutation[len(permutation) - 1]])
robust_monomial, l_norm = self.robustify_monomial(monomial)
robust_monomial = self.robustify_monomial(monomial)
monomial = robust_monomial.sub(solution['variables'])
values.append(monomial.cs[0])
return sum(values)
Expand Down

0 comments on commit b4ef96c

Please sign in to comment.