Ejemplo n.º 1
0
 def get_sparsity_in(self, i):
     n = nlpsol_out(i)
     if n == "f":
         return Sparsity.scalar()
     elif n in ("x", "lam_x"):
         return Sparsity.dense(self.nx)
     elif n in ("g", "lam_g"):
         return Sparsity.dense(self.ng)
     else:
         return Sparsity(0, 0)
Ejemplo n.º 2
0
 def get_sparsity_in(self, i):
     n = ca.nlpsol_out(i)
     if n == 'f':
         return ca.Sparsity.scalar()
     elif n in ('x', 'lam_x'):
         return ca.Sparsity.dense(self.nx)
     elif n in ('g', 'lam_g'):
         return ca.Sparsity.dense(self.ng)
     else:
         return ca.Sparsity(0, 0)
Ejemplo n.º 3
0
    def get_name_in(i: int) -> int:
        """
        Get the name of a variable

        Parameters
        ----------
        i: int
            The index of the variable

        Returns
        -------
        The name of the variable
        """

        return nlpsol_out(i)
Ejemplo n.º 4
0
    def eval(self, arg):
        darg = {}
        for (i, s) in enumerate(ca.nlpsol_out()):
            darg[s] = arg[i]

        solution = np.array(
            (darg['x'][:len(self.param_scale)] * self.param_scale).T)
        loss = darg['f']

        logger.record_tabular('loss', loss)
        logger.record_tabular('solution', solution)

        self.algo.solution = solution
        params, torch_params = self.algo.get_itr_snapshot(self.itr)
        logger.save_itr_params(self.itr, params, torch_params)

        logger.dump_tabular(with_prefix=False)

        self.itr += 1

        return [0]
Ejemplo n.º 5
0
    def get_sparsity_in(self, i: int) -> tuple:
        """
        Get the sparsity of a specific variable

        Parameters
        ----------
        i: int
            The index of the variable

        Returns
        -------
        The sparsity of the variable
        """

        n = nlpsol_out(i)
        if n == "f":
            return Sparsity.scalar()
        elif n in ("x", "lam_x"):
            return Sparsity.dense(self.nx)
        elif n in ("g", "lam_g"):
            return Sparsity.dense(self.ng)
        else:
            return Sparsity(0, 0)
Ejemplo n.º 6
0
 def get_name_in(i):
     return nlpsol_out(i)
Ejemplo n.º 7
0
 def get_name_in(self, i):
     return ca.nlpsol_out(i)