def configure(self):
        self.add('driver', IterateUntil())
        self.add('branchbound_algorithm', BranchBoundNonLinear(n_int = 2, n_contin = 0))
        #self.add('nonlinopt', BandBSLSQPdriver(n_x=2))
        self.add('nonlinopt', pyOptSparseDriver(n_x=2))
        self.nonlinopt.optimizer = "SNOPT"
        self.add('nonlin_test_prob', NonLinearTestProblem())

        #nonlin problem formulation`
        self.nonlinopt.add_parameter('nonlin_test_prob.x', low=0, high=1e3)

        self.nonlinopt.add_objective('nonlin_test_prob.f')
        self.nonlinopt.add_constraint('nonlin_test_prob.g1 < 0')
        self.nonlinopt.add_constraint('nonlin_test_prob.g2 < 0')

        #iteration hierachy
        self.driver.workflow.add(['branchbound_algorithm','nonlinopt'])
        self.nonlinopt.workflow.add('nonlin_test_prob')

        #data connections
        # Connect solver component with the Branch  and Bound Algorithm Component (return results)
        self.connect('nonlin_test_prob.x',     'branchbound_algorithm.xopt_current')
        self.connect('nonlin_test_prob.f',     'branchbound_algorithm.relaxed_obj_current')
        self.connect('nonlinopt.exit_flag',    'branchbound_algorithm.exitflag_NLP')


        # Connect Airline Allocation SubProblem Component with Branch  and Bound Algorithm Component and the solver
        # Connect Branch  and Bound Algorithm Component with the solver component
        self.connect('branchbound_algorithm.lb', 'nonlinopt.lb')
        self.connect('branchbound_algorithm.ub', 'nonlinopt.ub')

        self.driver.add_stop_condition('branchbound_algorithm.exec_loop != 0')
        self.driver.max_iterations = 1000000

        self.recorders=[JSONCaseRecorder('nonlintest.json')]
Example #2
0
    def configure(self):
        """ Creates a new Assembly containing a MultiFunction and an optimizer"""

        # pylint: disable=E1101

        # Create MultiFunction component instances
        self.add('multifunction', MultiFunction())

        # Create NSGA2 Optimizer instance
        self.add('driver', pyOptSparseDriver())

        # Driver process definition
        self.driver.workflow.add('multifunction')

        self.driver.print_results = False

        # NSGA2 Objective
        self.driver.add_objective('multifunction.f1_x')
        self.driver.add_objective('multifunction.f2_x')

        # NSGA2 Design Variable
        self.driver.add_parameter('multifunction.x1', low=0.1, high=1.0)
        self.driver.add_parameter('multifunction.x2', low=0.0, high=5.0)

        # NSGA2 Constraints
        self.driver.add_constraint('multifunction.g1_x >= 6.0')
        self.driver.add_constraint('multifunction.g2_x >= 1.0')
    def configure(self):
        """ Creates a new Assembly containing a Paraboloid and an optimizer"""

        # pylint: disable=E1101

        # Create Paraboloid component instances
        self.add('paraboloid', Paraboloid())

        # Create SNOPT Optimizer instance
        self.add('driver', pyOptSparseDriver(n_x=2))

        # Driver process definition
        self.driver.workflow.add('paraboloid')

        # SNOPT Objective
        self.driver.add_objective('paraboloid.f_xy')

        # SNOPT Design Variables
        self.driver.add_parameter('paraboloid.x', low=-50., high=50.)
        self.driver.add_parameter('paraboloid.y', low=-50., high=50.)

        self.driver.lb = [0.,0.]
        self.driver.ub = [5,100.0]

        # SNOPT Constraints
        self.driver.add_constraint('paraboloid.x-paraboloid.y >= 15.0')

        self.driver.print_results = False
    def configure(self):
        """ Creates a new Assembly containing a MultiFunction and an optimizer"""

        # pylint: disable=E1101

        # Create MultiFunction component instances
        self.add('multifunction', MultiFunction())

        # Create NSGA2 Optimizer instance
        self.add('driver', pyOptSparseDriver())

        # Driver process definition
        self.driver.workflow.add('multifunction')

        self.driver.print_results = False

        # NSGA2 Objective
        self.driver.add_objective('multifunction.f1_x')
        self.driver.add_objective('multifunction.f2_x')

        # NSGA2 Design Variable
        self.driver.add_parameter('multifunction.x1', low=0.1, high=1.0)
        self.driver.add_parameter('multifunction.x2', low=0.0, high=5.0)

        # NSGA2 Constraints
        self.driver.add_constraint('multifunction.g1_x >= 6.0')
        self.driver.add_constraint('multifunction.g2_x >= 1.0')
Example #5
0
    def configure(self):
        """ Creates a new Assembly containing a Paraboloid and an optimizer"""

        # pylint: disable=E1101

        # Create Paraboloid component instances
        self.add('paraboloid', Paraboloid())

        # Create SNOPT Optimizer instance
        self.add('driver', pyOptSparseDriver(n_x=2))

        # Driver process definition
        self.driver.workflow.add('paraboloid')

        # SNOPT Objective
        self.driver.add_objective('paraboloid.f_xy')

        # SNOPT Design Variables
        self.driver.add_parameter('paraboloid.x', low=-50., high=50.)
        self.driver.add_parameter('paraboloid.y', low=-50., high=50.)

        self.driver.lb = [0., 0.]
        self.driver.ub = [5, 100.0]

        # SNOPT Constraints
        self.driver.add_constraint('paraboloid.x-paraboloid.y >= 15.0')

        self.driver.print_results = False
    def configure(self):
        """ Creates a new Assembly containing ArrayParaboloid and an optimizer"""

        # pylint: disable=E1101

        self.add('paraboloid', ArrayParaboloid())
        self.add('driver', pyOptSparseDriver())
        self.driver.pyopt_diff = True
        self.driver.workflow.add('paraboloid')
        self.driver.add_objective('paraboloid.f_xy')
        self.driver.add_parameter('paraboloid.x', low=-50., high=50.)
        self.driver.add_constraint('paraboloid.x[0]-paraboloid.x[1] >= 15.0')
        self.driver.print_results = False
Example #7
0
    def configure(self):
        """ Creates a new Assembly containing ArrayParaboloid and an optimizer"""

        # pylint: disable=E1101

        self.add('paraboloid', ArrayParaboloid())
        self.add('driver', pyOptSparseDriver())
        self.driver.pyopt_diff = True
        self.driver.workflow.add('paraboloid')
        self.driver.add_objective('paraboloid.f_xy')
        self.driver.add_parameter('paraboloid.x', low=-50., high=50.)
        self.driver.add_constraint('paraboloid.x[0]-paraboloid.x[1] >= 15.0')
        self.driver.print_results = False
Example #8
0
    def configure(self):

        self.add('driver', pyOptSparseDriver(n_x=2))
        self.driver.optimizer = "SNOPT"
        self.add('prob', NonLinearTestProblem())

        self.driver.add_parameter('prob.x', low=0, high=1000)
        self.driver.gradient_options.fd_form = 'central'
        self.driver.gradient_options.fd_step = 1.0e-3
        self.driver.gradient_options.fd_step_type = 'relative'

        self.driver.add_objective('prob.f')
        self.driver.add_constraint('prob.g1 < 0')
        self.driver.add_constraint('prob.g2 < 0')
    def configure(self): 

        self.add('driver', pyOptSparseDriver(n_x=2))
        self.driver.optimizer = "SNOPT"
        self.add('prob', NonLinearTestProblem())

        self.driver.add_parameter('prob.x', low=0, high=1000)
        self.driver.gradient_options.fd_form = 'central'
        self.driver.gradient_options.fd_step = 1.0e-3
        self.driver.gradient_options.fd_step_type = 'relative'

        self.driver.add_objective('prob.f')
        self.driver.add_constraint('prob.g1 < 0')
        self.driver.add_constraint('prob.g2 < 0')
    def __init__(self):
        """Creates a new Assembly containing a MultiFunction and an optimizer"""

        # pylint: disable=E1101

        super(BenchMarkOptimization, self).__init__()

        # Create MultiFunction component instances
        self.add('benchmark', BenchMark())

        # Create ALPSO Optimizer instance
        self.add('driver', pyOptSparseDriver())

        # Driver process definition
        self.driver.workflow.add('benchmark')

        # PyOpt Flags
        self.driver.optimizer = 'ALPSO'
        self.driver.title = 'Bench mark problem 4 - Unconstrained'
        optdict = {}
        optdict['SwarmSize'] = 40
        optdict['maxOuterIter'] = 100
        optdict['maxInnerIter'] = 3
        optdict['minInnerIter'] = 3
        optdict['etol'] = 1e-4
        optdict['itol'] = 1e-4
        optdict['c1'] = 0.8
        optdict['c2'] = 0.8
        optdict['w1'] = 0.9
        optdict['nf'] = 5
        optdict['dt'] = 1.0
        optdict['vcrazy'] = 1e-4
        optdict['Scaling'] = 1
        optdict['seed'] = 1.0

        self.driver.options = optdict

        # ALPSO Objective
        self.driver.add_objective('benchmark.f_x')

        # ALPSO Design Variables
        self.driver.add_parameter('benchmark.x1', low=0, high=42)
        self.driver.add_parameter('benchmark.x2', low=0, high=42)
        self.driver.add_parameter('benchmark.x3', low=0, high=42)

        # ALPSO Constraints
        self.driver.add_constraint('benchmark.g1_x <= 0.0')
        self.driver.add_constraint('benchmark.h1_x <= 0.0')
Example #11
0
    def __init__(self):
        """Creates a new Assembly containing a MultiFunction and an optimizer"""

        # pylint: disable=E1101

        super(BenchMarkOptimization, self).__init__()

        # Create MultiFunction component instances
        self.add('benchmark', BenchMark())

        # Create ALPSO Optimizer instance
        self.add('driver', pyOptSparseDriver())

        # Driver process definition
        self.driver.workflow.add('benchmark')

        # PyOpt Flags
        self.driver.optimizer = 'ALPSO'
        self.driver.title = 'Bench mark problem 4 - Unconstrained'
        optdict = {}
        optdict['SwarmSize'] = 40
        optdict['maxOuterIter'] = 100
        optdict['maxInnerIter'] = 3
        optdict['minInnerIter'] = 3
        optdict['etol'] = 1e-4
        optdict['itol'] = 1e-4
        optdict['c1'] = 0.8
        optdict['c2'] = 0.8
        optdict['w1'] = 0.9
        optdict['nf'] = 5
        optdict['dt'] = 1.0
        optdict['vcrazy'] = 1e-4
        optdict['Scaling'] = 1
        optdict['seed'] = 1.0

        self.driver.options = optdict

        # ALPSO Objective
        self.driver.add_objective('benchmark.f_x')

        # ALPSO Design Variables
        self.driver.add_parameter('benchmark.x1', low=0, high=42)
        self.driver.add_parameter('benchmark.x2', low=0, high=42)
        self.driver.add_parameter('benchmark.x3', low=0, high=42)

        # ALPSO Constraints
        self.driver.add_constraint('benchmark.g1_x <= 0.0')
        self.driver.add_constraint('benchmark.h1_x <= 0.0')
Example #12
0
    def configure(self):
        self.add('driver', IterateUntil())
        self.add('branchbound_algorithm',
                 BranchBoundNonLinear(n_int=2, n_contin=0))
        #self.add('nonlinopt', BandBSLSQPdriver(n_x=2))
        self.add('nonlinopt', pyOptSparseDriver(n_x=2))
        self.nonlinopt.optimizer = "SNOPT"
        self.add('nonlin_test_prob', NonLinearTestProblem())

        #nonlin problem formulation`
        self.nonlinopt.add_parameter('nonlin_test_prob.x', low=0, high=1e3)

        self.nonlinopt.add_objective('nonlin_test_prob.f')
        self.nonlinopt.add_constraint('nonlin_test_prob.g1 < 0')
        self.nonlinopt.add_constraint('nonlin_test_prob.g2 < 0')

        #iteration hierachy
        self.driver.workflow.add(['branchbound_algorithm', 'nonlinopt'])
        self.nonlinopt.workflow.add('nonlin_test_prob')

        #data connections
        # Connect solver component with the Branch  and Bound Algorithm Component (return results)
        self.connect('nonlin_test_prob.x',
                     'branchbound_algorithm.xopt_current')
        self.connect('nonlin_test_prob.f',
                     'branchbound_algorithm.relaxed_obj_current')
        self.connect('nonlinopt.exit_flag',
                     'branchbound_algorithm.exitflag_NLP')

        # Connect Airline Allocation SubProblem Component with Branch  and Bound Algorithm Component and the solver
        # Connect Branch  and Bound Algorithm Component with the solver component
        self.connect('branchbound_algorithm.lb', 'nonlinopt.lb')
        self.connect('branchbound_algorithm.ub', 'nonlinopt.ub')

        self.driver.add_stop_condition('branchbound_algorithm.exec_loop != 0')
        self.driver.max_iterations = 1000000

        self.recorders = [JSONCaseRecorder('nonlintest.json')]
Example #13
0
num_cp = num_cp_init
while num_cp <= num_cp_max:

    x_range *= 1.852
    x_init = x_range * 1e3 * (
        1 - np.cos(np.linspace(0, 1, num_cp) * np.pi)) / 2 / 1e6
    M_init = np.ones(num_cp) * 0.82
    h_init = 10 * np.sin(np.pi * x_init / (x_range / 1e3))

    model = set_as_top(
        MissionSegment(num_elem=num_elem,
                       num_cp=num_cp,
                       x_pts=x_init,
                       surr_file='crm_surr'))

    model.replace('driver', pyOptSparseDriver())
    #model.replace('driver', SimpleDriver())
    model.driver.optimizer = 'SNOPT'
    model.driver.options = {'Iterations limit': 5000000}

    # Add parameters, objectives, constraints
    model.driver.add_parameter('h_pt', low=0.0, high=14.1)
    model.driver.add_objective('SysFuelObj.fuelburn')
    model.driver.add_constraint('SysHBspline.h[0] = 0.0')
    model.driver.add_constraint('SysHBspline.h[-1] = 0.0')
    model.driver.add_constraint('SysTmin.Tmin < 0.0')
    model.driver.add_constraint('SysTmax.Tmax < 0.0')
    model.driver.add_constraint('%.15f < SysGammaBspline.Gamma < %.15f' % \
                                (gamma_lb, gamma_ub), linear=True)

    # Initial value of the parameter
Example #14
0
start = time.time()
num_cp = num_cp_init
while num_cp <= num_cp_max:

    x_range *= 1.852
    x_init = x_range * 1e3 * (1-np.cos(np.linspace(0, 1, num_cp)*np.pi))/2/1e6
    #v_init = np.ones(num_cp)*2.5
    M_init = np.ones(num_cp)*0.8
    #M_init = np.ones(num_cp)*0.82
    h_init = 10 * np.sin(np.pi * x_init / (x_range/1e3))

    model = set_as_top(MissionSegment(num_elem=num_elem, num_cp=num_cp,
                                      x_pts=x_init, surr_file='../crm_surr'))

    model.replace('driver', pyOptSparseDriver())
    #model.replace('driver', SimpleDriver())
    model.driver.optimizer = 'SNOPT'
    model.driver.options = {'Iterations limit': 5000000, 
                            'Print file': os.path.join('plotting','range_sweep_data','SNOPT_%d_print.out' % num_cp)}

    # Add parameters, objectives, constraints
    model.driver.add_parameter('h_pt', low=0.0, high=14.1)
    model.driver.add_objective('SysFuelObj.fuelburn')
    model.driver.add_constraint('SysHi.h_i = 0.0')
    model.driver.add_constraint('SysHf.h_f = 0.0')
    model.driver.add_constraint('SysTmin.Tmin < 0.0')
    model.driver.add_constraint('SysTmax.Tmax < 0.0')
    model.driver.add_constraint('%.15f < SysGammaBspline.Gamma < %.15f' % \
                                (gamma_lb, gamma_ub), linear=True)
Example #15
0
        print alloc.SysProfit.profit
        #alloc.check_comp_derivatives()
        exit()

#    for irt in xrange(alloc.num_routes):
#        for inac in xrange(alloc.num_new_ac):
#            seg_name = 'Seg_%03i_%03i' % (irt,inac)
#            seg = alloc.get(seg_name)
#            sub_opt = setup_opt(seg)
#
#            sub_opt.run()
#
#            call(['mv', 'SNOPT_print.out', 'SNOPT_%03i_%03i_print.out' % (irt,inac)])
#            call(['rm', 'SNOPT_summary.out'])

    alloc.replace('driver', pyOptSparseDriver())
    alloc.driver.optimizer = 'SNOPT'
    alloc.driver.options = {'Iterations limit': 5000000}#, 'Verify level':3}
    # alloc.driver.gradient_options.lin_solver = "linear_gs"
    alloc.driver.gradient_options.lin_solver = 'petsc_ksp'
    # alloc.driver.gradient_options.maxiter = 1
    alloc.driver.gradient_options.derivative_direction = 'adjoint'
    alloc.driver.gradient_options.iprint = 0
    # alloc.driver.system_type = 'serial'

    alloc.driver.add_objective('profit')
    for irt in xrange(alloc.num_routes):
        for inac in xrange(alloc.num_new_ac):
            seg_name = 'Seg_%03i_%03i' % (irt,inac)
            alloc.driver.add_parameter(seg_name+'.h_pt', low=0.0, high=15.0) #14.1)
            alloc.driver.add_constraint(seg_name+'.h[0] = 0.0')