Пример #1
0
def plot_feasibility_simple_Wing(type_of_uncertainty_set, x, y, str1, val1, str2, val2, design_feasibility):
    plot_feasibilities(x, y, m)
    x.key.descr[str1] = val1
    y.key.descr[str2] = val2
    RM = RobustModel(m, type_of_uncertainty_set, linearizationTolerance=1e-4)
    RMsol = RM.robustsolve(verbosity=0, minNumOfLinearSections=20, maxNumOfLinearSections=40)
    print "nominal: ", {k: v for k, v in sol["freevariables"].items()
                        if k in m.varkeys and k.key.fix is True}
    print "robust: ", {k: v for k, v in RMsol["freevariables"].items()
                       if k in m.varkeys and k.key.fix is True}
    print 'cost', RMsol['cost']
    plot_feasibilities(x, y, m, RM, numberofsweeps=120, design_feasibility=design_feasibility, skipfailures=True)
    del x.key.descr[str1]
    del y.key.descr[str2]
Пример #2
0
def robustify_synthetic_model(the_model,
                              is_two_term,
                              is_boyd,
                              is_simple_model,
                              the_uncertainty_set,
                              the_min_number_of_linear_sections=3,
                              the_max_number_of_linear_sections=99,
                              the_verbosity=0,
                              the_linearization_tolerance=1e-3):
    the_robust_model = RobustModel(the_model,
                                   the_uncertainty_set,
                                   twoTerm=is_two_term,
                                   boyd=is_boyd,
                                   simpleModel=is_simple_model)
    the_robust_model_solution = the_robust_model.robustsolve(
        verbosity=the_verbosity,
        linearizationTolerance=the_linearization_tolerance,
        minNumOfLinearSections=the_min_number_of_linear_sections,
        maxNumOfLinearSections=the_max_number_of_linear_sections)
    return the_robust_model, the_robust_model_solution
Пример #3
0
def simulate_robust_model(
        the_model, the_method, the_uncertainty_set, the_gamma,
        the_directly_uncertain_vars_subs, the_number_of_iterations,
        the_linearization_tolerance, the_min_num_of_linear_sections,
        the_max_num_of_linear_sections, the_verbosity, the_nominal_solution,
        the_number_of_time_average_solves):
    print(the_method['name'] + ' under ' + the_uncertainty_set +
          ' uncertainty set: \n' + '\t' + 'gamma = %s\n' % the_gamma + '\t' +
          'minimum number of piecewise-linear sections = %s\n' %
          the_min_num_of_linear_sections + '\t' +
          'maximum number of piecewise-linear sections = %s\n' %
          the_max_num_of_linear_sections)

    the_robust_model = RobustModel(the_model,
                                   the_uncertainty_set,
                                   gamma=the_gamma,
                                   twoTerm=the_method['twoTerm'],
                                   boyd=the_method['boyd'],
                                   simpleModel=the_method['simpleModel'],
                                   nominalsolve=the_nominal_solution)
    the_robust_model_solution = the_robust_model.robustsolve(
        verbosity=the_verbosity,
        minNumOfLinearSections=the_min_num_of_linear_sections,
        maxNumOfLinearSections=the_max_num_of_linear_sections,
        linearizationTolerance=the_linearization_tolerance)

    the_robust_model_solve_time = the_robust_model_solution['soltime']
    for _ in xrange(the_number_of_time_average_solves - 1):
        the_robust_model_solve_time += the_robust_model.robustsolve(
            verbosity=0)['soltime']
    the_robust_model_solve_time = the_robust_model_solve_time / the_number_of_time_average_solves
    the_simulation_results = RobustGPTools.probability_of_failure(
        the_model,
        the_robust_model_solution,
        the_directly_uncertain_vars_subs,
        the_number_of_iterations,
        verbosity=0)
    return the_robust_model, the_robust_model_solution, the_robust_model_solve_time, the_simulation_results
Пример #4
0
def plot_feasibility_simple_Wing(type_of_uncertainty_set, axisvars, str1, val1, str2, val2, saveimg=False):
    if saveimg:
        x_name = axisvars[0].key.descr["name"]
        y_name = axisvars[1].key.descr["name"]
        for inval_chars in ["\\", ",", "{", "}"]:
            x_name = x_name.replace(inval_chars, "")
            y_name = y_name.replace(inval_chars, "")
    orig_plt = plot_feasibilities(axisvars, m)
    if saveimg:
        orig_plt.savefig("test_figs/%s_orig_%s_%s.png" % (type_of_uncertainty_set, x_name, y_name))
    axisvars[0].key.descr[str1] = val1
    axisvars[1].key.descr[str2] = val2
    RM = RobustModel(m, type_of_uncertainty_set, linearizationTolerance=1e-4)
    RMsol = RM.robustsolve(verbosity=0, minNumOfLinearSections=20, maxNumOfLinearSections=40)
    print("nominal: ", {k: v for k, v in list(sol["freevariables"].items())
                        if k in m.varkeys and k.key.fix is True})
    print("robust: ", {k: v for k, v in list(RMsol["freevariables"].items())
                       if k in m.varkeys and k.key.fix is True})
    print('cost', RMsol['cost'])
    robust_plt = plot_feasibilities(axisvars, m, RM, numberofsweeps=120, skipfailures=True)
    if saveimg:
        robust_plt.savefig("test_figs/%s_robust_%s_%s.png" % (type_of_uncertainty_set, x_name, y_name))
    del axisvars[0].key.descr[str1]
    del axisvars[1].key.descr[str2]
    return sol, robustsol

def plot_general_solutions(solarray, var1, var2, var3):
    points = ["o","*","-"]
    count = 0
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    for i in solarray:
        ax.plot(mag(i(var1.key)), mag(i(var2.key)),mag(i(var3.key)))
        count+=1
    ax.set_xlabel(var1.str_without())
    ax.set_ylabel(var2.str_without())
    ax.set_zlabel(var3.str_without())
    plt.title('3D Flight envelope')
    plt.show()

if __name__ == "__main__":
    m, subs = SimPleAC_setup()
    # Payload/range feasibility plot for nominal and robust aircraft
    var2 = m['W_{p_m}']
    var1 = m['Range_m']
    var1range = np.linspace(500,5000,24)*units('km')
    rm = None
    #plot_feasibilities(x, y, m, rm=rm, design_feasibility=True, skipfailures=True, numberofsweeps=20)
    sol , _, _, directly_uncertain_vars_subs = generate_model_properties(m, 1, 1)  # solving the SimPleAC
    rm = RobustModel(m, 'ellipsoidal', twoTerm=False, gamma=1)
    rmsol = rm.robustsolve()
    sol, robustsol = generate_flight_envelope(m, var1, var2, var1range, rm, rmsol)

    plot_general_solutions([sol,robustsol],var1,var2,m['W_{f_m}'])
Пример #6
0
    margin_subs = {
        k: v + np.sign(mag(sol['sensitivities']['constants'][k.key])) *
        k.key.pr * v / 100.0
        for k, v in m.substitutions.items()
        if k in m.varkeys and RobustGPTools.is_directly_uncertain(k)
    }

    # Model with margins
    mm = Model(m.cost, m, subs)
    mm.substitutions.update(margin_subs)
    msol = mm.localsolve(verbosity=2)

    # Model with box uncertainty
    bm = RobustModel(m,
                     'box',
                     twoTerm=True,
                     boyd=False,
                     simpleModel=False,
                     gamma=gamma)
    bsol = bm.robustsolve(verbosity=2)

    # Model with ellipsoidal uncertainty
    em = RobustModel(m,
                     'ellipsoidal',
                     twoTerm=True,
                     boyd=False,
                     simpleModel=False,
                     gamma=gamma)
    esol = em.robustsolve(verbosity=2)

    try:
        soltab = [sol, msol, bsol, esol]
Пример #7
0
                             for i in objectives.keys())
    # Nominal case must always be first!
    methods = ['nominal', 'ellipsoidal', 'box']
    marray = [[] for i in range(len(keyOrder))]
    counti = 0
    for i in range(len(keyOrder)):
        for j in methods:
            try:
                nm = Model(keyOrder[i] + minimizer * keyOrder[i].units, m,
                           m.substitutions)
            except:
                nm = Model(keyOrder[i] + minimizer, m, m.substitutions)
            if j == 'nominal':
                marray[counti].append(nm)
            else:
                nm = RobustModel(nm, j, twoTerm=False, gamma=1)
                marray[counti].append(nm)
        counti += 1

    solutions = gen_SimPleAC_radar(marray, methods, objectives, keyOrder,
                                   baseobj)

    colors = ['blue', 'red', 'green']
    directory = 'savefigs'

    # # Saving data
    [data, maxesindata,
     minsindata] = generate_radar_data(solutions, objectives, keyOrder,
                                       baseobj)
    # Placeholder for plot debugging and proper spoke labeling
    # plot_radar_data(solutions, methods, data, maxesindata, minsindata)
Пример #8
0
from robust.robust import RobustModel
from SimPleAC_setup import SimPleAC_setup
from robust.signomial_simple_wing.models import simple_ac
from robust.simulations.simulate import generate_model_properties
from robust.robust_gp_tools import RobustGPTools

model, subs = SimPleAC_setup()  # the SimPleAC model
model_solution, _, _, directly_uncertain_vars_subs = generate_model_properties(
    model, 1, 1, 'uniform')  # solving the SimPleAC
# and generating a realization of the uncertain parameters

# robust_model = RobustModel(model, 'box', twoTerm = False, Gamma = 1) # generates the robust model

robust_model = RobustModel(model, 'ellipsoidal', twoTerm=False,
                           Gamma=1)  # generates the robust model
robust_model_solution = robust_model.robustsolve(
    verbosity=0)  # solve the robust model

# Below, we are testing the SimPleAC model against failure. The free variables with attribute fixed=True are fixed using
# the robust solution, and the uncertain parameters are replaced by the realizations generated above. The model is then
# solved to check if a feasible solution exists.
designed_model = RobustGPTools.DesignedModel(model, robust_model_solution,
                                             directly_uncertain_vars_subs[0])
designed_model_solution = designed_model.localsolve()
# The designed model is not converging although it has the same set of constraints as the original model by with
# different substitutions