Пример #1
0
    def solve_problem(self, target_variable, maximize=False):
        """
        Solve the linear programming problem
        """
        target_column = self.var_corr[target_variable]

        c = [0.0] * self.variable_count
        if maximize:
            c[target_column] = -1.0
        else:
            c[target_column] = 1.0
        sol = lp_solver_factory.apply(c,
                                      self.Aub,
                                      self.bub,
                                      self.Aeq,
                                      self.beq,
                                      variant=DEFAULT_LP_SOLVER_VARIANT)
        parameters_points = {
            "maximize": maximize,
            "return_when_none": True,
            "var_corr": self.var_corr
        }

        return lp_solver_factory.get_points_from_sol(
            sol,
            parameters=parameters_points,
            variant=DEFAULT_LP_SOLVER_VARIANT)
Пример #2
0
def __compute_exact_heuristic_new_version(sync_net, a_matrix, h_cvx, g_matrix,
                                          cost_vec, incidence_matrix, marking,
                                          fin_vec):
    m_vec = incidence_matrix.encode_marking(marking)
    b_term = [i - j for i, j in zip(fin_vec, m_vec)]
    b_term = np.matrix([x * 1.0 for x in b_term]).transpose()

    if DEFAULT_LP_SOLVER_VARIANT == lp_solver_factory.CVXOPT_SOLVER_CUSTOM_ALIGN:
        b_term = matrix(b_term)

    parameters_solving = {"solver": "glpk"}

    sol = lp_solver_factory.apply(cost_vec,
                                  g_matrix,
                                  h_cvx,
                                  a_matrix,
                                  b_term,
                                  parameters=parameters_solving,
                                  variant=DEFAULT_LP_SOLVER_VARIANT)
    prim_obj = lp_solver_factory.get_prim_obj_from_sol(
        sol, variant=DEFAULT_LP_SOLVER_VARIANT)
    points = lp_solver_factory.get_points_from_sol(
        sol, variant=DEFAULT_LP_SOLVER_VARIANT)

    prim_obj = prim_obj if prim_obj is not None else sys.maxsize
    points = points if points is not None else [0.0] * len(
        sync_net.transitions)

    return prim_obj, points
Пример #3
0
def __compute_exact_heuristic(sync_net, incidence_matrix, marking, cost_vec,
                              fin_vec):
    """
    Computes an exact heuristic using an LP based on the marking equation.

    Parameters
    ----------
    :param sync_net: synchronous product net
    :param incidence_matrix: incidence matrix
    :param marking: marking to start from
    :param cost_vec: cost vector
    :param fin_vec: marking to reach

    Returns
    -------
    :return: h: heuristic value, x: solution vector
    """
    m_vec = incidence_matrix.encode_marking(marking)
    g_matrix = -np.eye(len(sync_net.transitions))
    h_cvx = np.zeros(len(sync_net.transitions))
    a_matrix = incidence_matrix.a_matrix
    b_term = [i - j for i, j in zip(fin_vec, m_vec)]

    cost_vec = [x * 1.0 for x in cost_vec]
    a_matrix = np.asmatrix(a_matrix).astype(np.float64)
    h_cvx = np.matrix([x * 1.0 for x in h_cvx]).transpose()
    b_term = np.matrix([x * 1.0 for x in b_term]).transpose()

    parameters_solving = {"solver": "glpk"}

    sol = lp_solver_factory.apply(cost_vec,
                                  g_matrix,
                                  h_cvx,
                                  a_matrix,
                                  b_term,
                                  parameters=parameters_solving,
                                  variant=DEFAULT_LP_SOLVER_VARIANT)
    prim_obj = lp_solver_factory.get_prim_obj_from_sol(
        sol, variant=DEFAULT_LP_SOLVER_VARIANT)
    points = lp_solver_factory.get_points_from_sol(
        sol, variant=DEFAULT_LP_SOLVER_VARIANT)

    prim_obj = prim_obj if prim_obj is not None else sys.maxsize
    points = points if points is not None else [0.0] * len(
        sync_net.transitions)

    return prim_obj, points
Пример #4
0
def __compute_exact_heuristic_new_version(sync_net,
                                          a_matrix,
                                          h_cvx,
                                          g_matrix,
                                          cost_vec,
                                          incidence_matrix,
                                          marking,
                                          fin_vec,
                                          variant,
                                          use_cvxopt=False):
    m_vec = incidence_matrix.encode_marking(marking)
    b_term = [i - j for i, j in zip(fin_vec, m_vec)]
    b_term = np.matrix([x * 1.0 for x in b_term]).transpose()

    if use_cvxopt:
        # not available in the latest version of PM4Py
        from cvxopt import matrix

        b_term = matrix(b_term)

    parameters_solving = {"solver": "glpk"}

    sol = lp_solver_factory.apply(cost_vec,
                                  g_matrix,
                                  h_cvx,
                                  a_matrix,
                                  b_term,
                                  parameters=parameters_solving,
                                  variant=variant)
    prim_obj = lp_solver_factory.get_prim_obj_from_sol(sol, variant=variant)
    points = lp_solver_factory.get_points_from_sol(sol, variant=variant)

    prim_obj = prim_obj if prim_obj is not None else sys.maxsize
    points = points if points is not None else [0.0] * len(
        sync_net.transitions)

    return prim_obj, points