Exemple #1
0
 def assign_timepoint(self, assigned_time, node_id):
     stn = copy.deepcopy(self.stn)
     minimal_network = get_minimal_network(stn)
     if minimal_network:
         minimal_network.assign_timepoint(assigned_time, node_id, force=True)
         if self.stp_solver.is_consistent(minimal_network):
             self.stn.assign_timepoint(assigned_time, node_id, force=True)
             return
     node = self.stn.get_node(node_id)
     raise InconsistentAssignment(assigned_time, node.task_id, node.node_type)
Exemple #2
0
    def fpc_algorithm(stn):
        """ Computes the dispatchable graph of an stn using
        full path consistency

        :param stn: stn (object)
        """
        dispatchable_graph = get_minimal_network(stn)
        if dispatchable_graph is None:
            return
        risk_metric = 1
        return risk_metric, dispatchable_graph
Exemple #3
0
def srea(inputstn,
         debug=False,
         debugLP=False,
         returnAlpha=True,
         decouple=False,
         lb=0.0,
         ub=0.999):

    """ Runs the SREA algorithm on an input STN
    @param inputstn The STN that we are running SREA on
    @param debug Print optional status messages about alpha levels
    @param debugLP Print optional status messages about each run of the LP
    @param lb The starting lower bound on alpha for the binary search
    @param ub The starting upper bound on alpha for the binary search

    @returns a tuple (alpha, outputstn) if there is a solution,
    or None if there is no solution
    """

    stn = copy.deepcopy(inputstn)

    # dictionary of alphas for binary search
    alphas = {i: i / 1000.0 for i in range(1001)}

    # bounds for binary search
    lower = ceil(lb * 1000) - 1
    upper = floor(ub * 1000) + 1

    result = None

    # set up LP
    if not decouple:
        stn = get_minimal_network(stn)
        if stn is None:
            return result
        if debug:
            logger.debug("Minimal STN %s: ", stn)
    bounds, deltas, probBase = setUpLP(stn, decouple)

    if debug:
        logger.debug("probBase: %s ", probBase)

    # First run binary search on alpha
    while upper - lower > 1:
        alpha = alphas[(upper + lower) // 2]
        if debug:
            logger.debug('trying alpha %s', alpha)

        # run the LP
        probContainer = (bounds, deltas, probBase.copy())
        LPbounds = srea_LP(stn,
                           alpha,
                           decouple,
                           debug=debugLP,
                           probContainer=probContainer)

        # LP was feasible, try lower alpha
        if LPbounds is not None:
            upper = (upper + lower) // 2
            result = (alpha, LPbounds)
        # LP was infeasable, try higher alpha
        else:
            lower = (upper + lower) // 2

        # finished our search, load the smallest alpha decoupling
        if upper - lower <= 1:
            if result is not None:
                alpha, LPbounds = result
                if debug:
                    logger.debug(
                        'modifying STN with lowest good alpha, %s', alpha)

                for i, sign in LPbounds:
                    if sign == '+':
                        stn.update_edge_weight(
                            0, i, ceil(bounds[(i, '+')].varValue))
                    else:
                        stn.update_edge_weight(
                            i, 0, ceil(-bounds[(i, '-')].varValue))

                if returnAlpha:
                    return alpha, stn
                else:
                    return stn
    # skip the rest if there was no decoupling at all
    if result is None:
        if debug:
            logger.warning('could not produce feasible LP.')
        return None

    # Fail here
    assert(False)
Exemple #4
0
 def is_consistent(stn):
     minimal_network = get_minimal_network(stn)
     if minimal_network:
         return True
     else:
         return False