Example #1
0
    def _draw_constraints_node(self, g: Digraph.subgraph, phase_idx: int):
        """
        Draw the node which contains the information related to the constraints

        Parameters
        ----------
        g: Digraph.subgraph
            The subgraph to which the node is attached
        phase_idx: int
            The index of the current phase
        """

        list_constraints = []

        for constraint in self.ocp.nlp[phase_idx].g:
            constraints_str = ""
            node_index = self._analyze_nodes(phase_idx, constraint[0])
            constraints_str += self._constraint_to_str(
                constraint[0]["constraint"])
            list_constraints.append([constraints_str, node_index])

        all_constraints_str = "<b>Constraints</b><br/>"
        if len(list_constraints) != 0:
            for constraint in list_constraints:
                all_constraints_str += constraint[0]
                all_constraints_str += f"Shooting nodes index: {constraint[1]}<br/><br/>"
        else:
            all_constraints_str = "<b>Constraints</b><br/> No constraint set"
        g.node(f"constraints_node_{phase_idx}", f"""<{all_constraints_str}>""")
Example #2
0
    def _draw_parameter_node(self, g: Digraph.subgraph, phase_idx: int,
                             param_idx: int, parameter: Parameter):
        """
        Draw the node which contains the information related to the parameters

        Parameters
        ----------
        g: Digraph.subgraph
            The subgraph to which the node is attached
        phase_idx: int
            The index of the current phase
        param_idx: int
            The index of the parameter
        parameter: Parameter
            The parameter containing all the information to display
        """

        initial_guess, min_bound, max_bound = self._scaling_parameter(
            parameter)
        node_str = f"<u><b>{parameter.name[0].upper() + parameter.name[1:]}</b></u><br/>"
        node_str += f"<b>Size</b>: {parameter.size}<br/>"
        node_str += f"<b>Initial guesses</b>: {self._vector_layout(initial_guess, parameter.size)}<br/><br/>"
        if parameter.penalty_list is not None:
            node_str += f"<b>Objective</b>: {self._get_parameter_function_name(parameter)} <br/>"
            node_str += f"<b>Min bound</b>: {self._vector_layout(min_bound, parameter.size)} <br/>"
            node_str += f"<b>Max bound</b>: {self._vector_layout(max_bound, parameter.size)} <br/>"
            node_str += (
                f"{f'<b>Target</b>: {self._vector_layout(parameter.penalty_list.sliced_target, parameter.size, param=True)} <br/>'}"
                if parameter.penalty_list.sliced_target is not None else "")
            node_str += f"<b>Quadratic</b>: {parameter.penalty_list.quadratic} <br/>"
        g.node(f"param_{phase_idx}{param_idx}", f"""<{node_str}>""")
Example #3
0
    def _draw_lagrange_node(self, g: Digraph.subgraph, phase_idx: int):
        """
        Draw the node which contains the information related to the Lagrange objectives

        Parameters
        ----------
        g: Digraph.subgraph
            The subgraph to which the node is attached
        phase_idx: int
            The index of the current phase
        """

        lagrange_str = self._lagrange_to_str(self.ocp.nlp[phase_idx].J)[0]
        node_str = f"<b>Lagrange</b><br/>{lagrange_str}"
        g.node(f"lagrange_{phase_idx}", f"""<{node_str}>""")
Example #4
0
    def _draw_nlp_node(self, g: Digraph.subgraph, phase_idx: int):
        """
        Draw the node which contains the information related to one of the phases (ie. the name of the model,
        the phase duration, the number of shooting nodes, the dynamics, the ODE)

        Parameters
        ----------
        g: Digraph.subgraph
            The subgraph to which the node is attached
        phase_idx: int
            The index of the current phase
        """

        node_str = f"<b>Model</b>: {self.ocp.nlp[phase_idx].model.path().filename().to_string()}.{self.ocp.nlp[phase_idx].model.path().extension().to_string()}<br/>"
        node_str += f"<b>Phase duration</b>: {round(self.ocp.nlp[phase_idx].t_initial_guess, 2)} s<br/>"
        node_str += f"<b>Shooting nodes</b>: {self.ocp.nlp[phase_idx].ns}<br/>"
        node_str += f"<b>Dynamics</b>: {self.ocp.nlp[phase_idx].dynamics_type.type.name}<br/>"
        node_str += f"<b>ODE</b>: {self.ocp.nlp[phase_idx].ode_solver.rk_integrator.__name__}"
        g.node(f"nlp_node_{phase_idx}", f"""<{node_str}>""")
Example #5
0
    def _draw_parameter_node(self, g: Digraph.subgraph, phase_idx: int,
                             param_idx: int, parameter: Parameter):
        """
        Draw the node which contains the information related to the parameters

        Parameters
        ----------
        g: Digraph.subgraph
            The subgraph to which the node is attached
        phase_idx: int
            The index of the current phase
        param_idx: int
            The index of the parameter
        parameter: Parameter
            The parameter containing all the information to display
        """

        initial_guess, min_bound, max_bound, scaling = self._scaling_parameter(
            parameter)
        node_str = f"<u><b>{parameter.name[0].upper() + parameter.name[1:]}</b></u><br/>"
        node_str += f"<b>Size</b>: {parameter.size}<br/>"
        node_str += f"<b>Scaling</b>: {scaling}<br/>"
        node_str += f"<b>Initial guess</b>: {initial_guess}<br/>"
        node_str += f"<b>Min bound</b>: {min_bound} <br/>"
        node_str += f"<b>Max bound</b>: {max_bound} <br/><br/>"
        if parameter.penalty_list is not None:
            size_initial_guess = len(parameter.initial_guess.init[0])
            size_sliced_target = len(parameter.penalty_list.sliced_target[0])
            scaling = [
                parameter.scaling[i][j] for i in range(parameter.size)
                for j in range(size_initial_guess)
            ]
            sliced_target_without_scaling = [
                parameter.penalty_list.sliced_target[i][j] / scaling[i]
                for i in range(parameter.size)
                for j in range(size_sliced_target)
            ]
            node_str += f"<b>Objective</b>: {self._get_parameter_function_name(parameter)} <br/>"
            node_str += (
                f"{f'<b>Target</b>: {self._vector_layout(sliced_target_without_scaling)} <br/>'}"
                if parameter.penalty_list.sliced_target is not None else "")
            node_str += f"<b>Quadratic</b>: {parameter.penalty_list.quadratic} <br/>"
        g.node(f"param_{phase_idx}{param_idx}", f"""<{node_str}>""")
Example #6
0
    def _draw_mayer_node(self, g: Digraph.subgraph, phase_idx: int):
        """
        Draw the node which contains the information related to the Mayer objectives

        Parameters
        ----------
        g: Digraph.subgraph
            The subgraph to which the node is attached
        phase_idx: int
            The index of the current phase
        """

        list_mayer_objectives = self._mayer_to_str(self.ocp.nlp[phase_idx].J)
        all_mayer_str = "<b>Mayer</b><br/>"
        if len(list_mayer_objectives) != 0:
            for objective in list_mayer_objectives:
                all_mayer_str += objective[1]
                all_mayer_str += f"Shooting nodes index: {objective[0]}<br/><br/>"
        else:
            all_mayer_str = "<b>Mayer</b><br/> No Mayer set"
        g.node(f"mayer_node_{phase_idx}", f"""<{all_mayer_str}>""")