예제 #1
0
    def init_opt_set_initial(self, x_init):
        """ Set the initial point of the NLP.

        Parameters:
            x_init --- The initial guess vector.
        """
        if self._jmi_model._dll.jmi_init_opt_set_initial(
                self._jmi_init_opt, x_init) is not 0:
            raise jmi.JMIException("Setting the initial point failed.")
예제 #2
0
 def init_opt_f(self, f):
     """ 
     Get the cost function value at a given point in search space.
     
     Parameters:
         f -- Value of the cost function. (Return)
     
     """
     if self._jmi_model._dll.jmi_init_opt_f(self._jmi_init_opt, f) is not 0:
         raise jmi.JMIException("Getting the cost function failed.")
예제 #3
0
 def init_opt_ipopt_set_int_option(self, key, val):
     """
     Set Ipopt integer option.
     
     Parameters:
         key -- Name of option.
         val -- Value of option.
         
     """
     if self._nlp_init._jmi_model._dll.jmi_init_opt_ipopt_set_int_option(
             self._ipopt_init, key, val) is not 0:
         raise jmi.JMIException("Setting int option failed.")
예제 #4
0
 def init_opt_h(self, res):
     """ 
     Get the residual of the equality constraints h.
     
     Parameters:
         res -- The residual of the equality constraints. (Return)
     
     """
     if self._jmi_model._dll.jmi_init_opt_h(self._jmi_init_opt,
                                            res) is not 0:
         raise jmi.JMIException(
             "Getting the residual of the equality constraints failed.")
예제 #5
0
 def init_opt_dh(self, jac):
     """ 
     Get the Jacobian of the residual of the equality constraints.
     
     Parameters:
         jac -- The Jacobian of the residual of the equality constraints. (Return)
     
     """
     if self._jmi_model._dll.jmi_init_opt_dh(self._jmi_init_opt,
                                             jac) is not 0:
         raise jmi.JMIException(
             "Getting the Jacobian of the residual of the equality constraints."
         )
예제 #6
0
 def init_opt_set_bounds(self, x_lb, x_ub):
     """ 
     Set the upper and lower bounds of the optimization variables.
     
     Parameters:
         x_lb -- The lower bounds vector. (Return)
         x_ub -- The upper bounds vector. (Return)
     
     """
     if self._jmi_model._dll.jmi_init_opt_set_bounds(
             self._jmi_init_opt, x_lb, x_ub) is not 0:
         raise jmi.JMIException(
             "Getting upper and lower bounds of the optimization variables failed."
         )
예제 #7
0
 def init_opt_dh_nz_indices(self, irow, icol):
     """ 
     Get the indices of the non-zeros in the equality constraint Jacobian.
     
     Parameters:
         irow -- 
             Row indices of the non-zero entries in the Jacobian of the 
             residual of the equality constraints. (Return)
         icol -- 
             Column indices of the non-zero entries in the Jacobian of the 
             residual of the equality constraints. (Return)
     
     """
     if self._jmi_model._dll.jmi_init_opt_dh_nz_indices(
             self._jmi_init_opt, irow, icol) is not 0:
         raise jmi.JMIException(
             "Getting the indices of the non-zeros in the equality constraint Jacobian failed."
         )
예제 #8
0
 def init_opt_get_dimensions(self):
     """ 
     Get the number of variables and the number of constraints in the 
     problem.
     
     Returns:
         Tuple with the number of variables in the NLP problem, equality constraints,
         and non-zeros in the Jacobian of the equality constraints respectively. 
         
     """
     n_x = ct.c_int()
     n_h = ct.c_int()
     dh_n_nz = ct.c_int()
     if self._jmi_model._dll.jmi_init_opt_get_dimensions(
             self._jmi_init_opt, byref(n_x), byref(n_h),
             byref(dh_n_nz)) is not 0:
         raise jmi.JMIException(
             "Getting the number of variables and constraints failed.")
     return n_x.value, n_h.value, dh_n_nz.value
예제 #9
0
    def __init__(self, nlp_init):
        """ 
        Class for solving a DAE initialization problem my means
        of optimization using IPOPT.
        
        Parameters:
            nlp_init -- NLPInitialization object.
        
        """

        self._nlp_init = nlp_init
        self._ipopt_init = ct.c_voidp()

        self._set_initOpt_typedefs()

        try:
            assert self._nlp_init._jmi_model._dll.jmi_init_opt_ipopt_new(byref(self._ipopt_init),
                                                                         self._nlp_init._jmi_init_opt) == 0, \
                   "jmi_init_opt_ipopt_new returned non-zero"
        except AttributeError, e:
            raise jmi.JMIException(
                "Can not create InitializationOptimizer object. Please recompile model with target='ipopt"
            )
예제 #10
0
 def init_opt_ipopt_solve(self):
     """ Solve the NLP problem."""
     if self._nlp_init._jmi_model._dll.jmi_init_opt_ipopt_solve(
             self._ipopt_init) is not 0:
         raise jmi.JMIException("Solving IPOPT failed.")
예제 #11
0
    def __init__(self, model):
        """
        Constructor where main data structure is created. 
        
        Initial guesses, lower and upper bounds and linearity information is 
        set for optimized parameters, derivatives, states, inputs and 
        algebraic variables. These values are taken from the XML files created 
        at compilation.
        
        Parameters:
            model -- The Model object.
        
        """
        self._jmi_init_opt = ct.c_voidp()
        self._model = model
        self._jmi_model = model.jmimodel

        _n_p_free = 0
        _p_free_indices = N.ones(_n_p_free, dtype=int)

        # Initialization
        _p_free_start = N.zeros(_n_p_free)  # Not supported
        _dx_start = N.zeros(model._n_dx.value)
        _x_start = N.zeros(model._n_x.value)
        _w_start = N.zeros(model._n_w.value)

        # Bounds
        _p_free_lb = -1.0e20 * N.ones(_n_p_free)  # Not supported
        _dx_lb = -1.0e20 * N.ones(model._n_dx.value)
        _x_lb = -1.0e20 * N.ones(model._n_x.value)
        _w_lb = -1.0e20 * N.ones(model._n_w.value)

        _p_free_ub = 1.0e20 * N.ones(_n_p_free)
        _dx_ub = 1.0e20 * N.ones(model._n_dx.value)
        _x_ub = 1.0e20 * N.ones(model._n_x.value)
        _w_ub = 1.0e20 * N.ones(model._n_w.value)

        self._set_start_values(_p_free_start, _dx_start, _x_start, _w_start)
        self._set_lb_values(_p_free_lb, _dx_lb, _x_lb, _w_lb)
        self._set_ub_values(_p_free_ub, _dx_ub, _x_ub, _w_ub)

        _linearity_information_provided = 0
        # Not supported
        _p_free_lin = N.ones(_n_p_free, dtype=int)
        _dx_lin = N.ones(model._n_dx.value, dtype=int)
        _x_lin = N.ones(model._n_x.value, dtype=int)
        _w_lin = N.ones(model._n_w.value, dtype=int)

        #         self._set_lin_values(_p_opt_lin, _dx_lin, _x_lin,_w_lin)

        self._set_typedef_init_opt_new()
        try:
            assert model.jmimodel._dll.jmi_init_opt_new(byref(self._jmi_init_opt), model.jmimodel._jmi,
                                                        _n_p_free,_p_free_indices,
                                     _p_free_start, _dx_start, _x_start,
                                     _w_start,
                                     _p_free_lb, _dx_lb, _x_lb,
                                     _w_lb,
                                     _p_free_ub, _dx_ub, _x_ub,
                                      _w_ub,
                                     _linearity_information_provided,
                                     _p_free_lin, _dx_lin, _x_lin, _w_lin,
                                                          jmi.JMI_DER_CPPAD) is 0, \
                                     " jmi_opt_lp_new returned non-zero."
        except AttributeError, e:
            raise jmi.JMIException("Can not create NLPInitialization object.")