Example #1
0
 def createConstraints(problem, variable):
     problem += lpSum(choiceVariables) <= 1, "Distribution"
     for choiceClass, height in state.getCurrentClassHeights().items():
         problem += createLpSum(choiceClass, choiceNames, choiceVariables) >= \
             height, classNames[choiceClass] + " height"
     for agent in state.getActiveAgents():
         problem += createLpSum(state.getCurrentAgentChoiceClass(agent),
                                choiceNames, choiceVariables) >= \
             state.getAgentHeight(agent) + variable * state.getAgentSpeed(agent), \
             agentNames[agent] + " push"
Example #2
0
 def createConstraints(problem, variable):
     problem += lpSum(choiceVariables) <= 1, "Distribution"
     for choiceClass, height in state.getCurrentClassHeights().items():
         problem += createLpSum(choiceClass, choiceNames, choiceVariables) >= \
             height, classNames[choiceClass] + " height"
     for agent in state.getActiveAgents():
         problem += createLpSum(state.getCurrentAgentChoiceClass(agent),
                                choiceNames, choiceVariables) >= \
             state.getAgentHeight(agent) + variable * state.getAgentSpeed(agent), \
             agentNames[agent] + " push"
Example #3
0
def computeLambda(state, maximumTime=1.0):
    activeAgents = state.getActiveAgents()
    agentNames = getUniqueNames(activeAgents, prefix="Agent ")
    classNames = getUniqueNames(state.getChoiceClasses(), prefix="Class ")
    choiceNames = getUniqueNames(state.getChoices(), prefix="")

    choiceVariables = LpVariable.dicts("p", choiceNames.values(), lowBound=0)
    lambdaVariable = LpVariable("l", lowBound=0.0, upBound=maximumTime)

    def createConstraints(problem, variable):
        problem += lpSum(choiceVariables) <= 1, "Distribution"
        for choiceClass, height in state.getCurrentClassHeights().items():
            problem += createLpSum(choiceClass, choiceNames, choiceVariables) >= \
                height, classNames[choiceClass] + " height"
        for agent in state.getActiveAgents():
            problem += createLpSum(state.getCurrentAgentChoiceClass(agent),
                                   choiceNames, choiceVariables) >= \
                state.getAgentHeight(agent) + variable * state.getAgentSpeed(agent), \
                agentNames[agent] + " push"

    problem = LpProblem("Lambda", LpMaximize)
    createConstraints(problem, lambdaVariable)
    problem.setObjective(lambdaVariable)
    checkPulpStatus(problem.solve(state.getSettings().getSolver()))
    lambdaOpt = lambdaVariable.value()

    bouncingAgents = []
    stringAgents = []  #TODO just a workaround; find better solution
    for currentAgent in activeAgents:
        print "Current agent: " + agentNames[
            currentAgent]  # name is off by one
        problem = LpProblem(agentNames[currentAgent], LpMaximize)
        createConstraints(problem, lambdaOpt)
        (choiceClass, height, speed) = state.getAgentData(currentAgent)
        # print "Choice Class: " + repr(choiceClass) + ",
        print "height: " + repr(height) + " , speed: " + repr(speed)
        problem.setObjective(
            createLpSum(choiceClass, choiceNames, choiceVariables) -
            lambdaOpt * speed - height)
        checkPulpStatus(problem.solve(state.getSettings().getSolver()))
        value = problem.objective.value()
        # print "value: " + repr(value) + "\n"
        if not state.getSettings().isNonnegative(value):
            raise ValueError(
                str(value) + " negative while determining bounce of " +
                repr(currentAgent) + " from " + repr(choiceClass) + "@" +
                str(height) + "/" + str(speed))
        if state.getSettings().isClose(value, 0):
            bouncingAgents.append(currentAgent)
            stringAgents.append(int(currentAgent.getName()))
        print "climbing time: " + repr(lambdaOpt) + ", bouncingAgents: " + str(
            stringAgents) + "\n"
        # print map(Agent.getName(), bouncingAgents)
    return (lambdaOpt, bouncingAgents)
Example #4
0
def computeLambda(state, maximumTime=1.0):
    activeAgents = state.getActiveAgents()
    agentNames = getUniqueNames(activeAgents, prefix="Agent ")
    classNames = getUniqueNames(state.getChoiceClasses(), prefix="Class ")
    choiceNames = getUniqueNames(state.getChoices(), prefix="")

    choiceVariables = LpVariable.dicts("p", choiceNames.values(), lowBound=0)
    lambdaVariable = LpVariable("l", lowBound=0.0, upBound=maximumTime)

    def createConstraints(problem, variable):
        problem += lpSum(choiceVariables) <= 1, "Distribution"
        for choiceClass, height in state.getCurrentClassHeights().items():
            problem += createLpSum(choiceClass, choiceNames, choiceVariables) >= \
                height, classNames[choiceClass] + " height"
        for agent in state.getActiveAgents():
            problem += createLpSum(state.getCurrentAgentChoiceClass(agent),
                                   choiceNames, choiceVariables) >= \
                state.getAgentHeight(agent) + variable * state.getAgentSpeed(agent), \
                agentNames[agent] + " push"

    problem = LpProblem("Lambda", LpMaximize)
    createConstraints(problem, lambdaVariable)
    problem.setObjective(lambdaVariable)
    checkPulpStatus(problem.solve(state.getSettings().getSolver()))
    lambdaOpt = lambdaVariable.value()

    bouncingAgents = []
    stringAgents = [] #TODO just a workaround; find better solution
    for currentAgent in activeAgents:
	print "Current agent: " + agentNames[currentAgent] # name is off by one
        problem = LpProblem(agentNames[currentAgent], LpMaximize)
        createConstraints(problem, lambdaOpt)
        (choiceClass, height, speed) = state.getAgentData(currentAgent)
	# print "Choice Class: " + repr(choiceClass) + ", 
	print "height: " + repr(height) + " , speed: " + repr(speed)
        problem.setObjective(createLpSum(choiceClass, choiceNames, choiceVariables)
                             - lambdaOpt * speed - height)
        checkPulpStatus(problem.solve(state.getSettings().getSolver()))
        value = problem.objective.value()
	# print "value: " + repr(value) + "\n"
        if not state.getSettings().isNonnegative(value):
            raise ValueError(str(value) + " negative while determining bounce of " +
                             repr(currentAgent) + " from " + repr(choiceClass) +
                             "@" + str(height) + "/" + str(speed))
        if state.getSettings().isClose(value, 0):
            bouncingAgents.append(currentAgent)
	    stringAgents.append(int(currentAgent.getName()))
	print "climbing time: " + repr(lambdaOpt) + ", bouncingAgents: " + str(stringAgents) + "\n"	
	# print map(Agent.getName(), bouncingAgents)
    return (lambdaOpt, bouncingAgents)
def computeLambda(state, maximumTime=1.0):
    '''
    @type state: SSRState
    @type maximumTime: float
    '''
    towerNames = getUniqueNames(state.getTowers(), prefix="T")
    choiceNames = getUniqueNames(state.getChoices(), prefix="")
    choiceVariables = LpVariable.dicts("p", choiceNames.values(), lowBound=0.0)
    lambdaVariable = LpVariable("l", lowBound=0.0, upBound=maximumTime)

    def createConstraints(problem, variable):
        problem += lpSum(choiceVariables) <= 1, "Distribution"
        for tower, towerName in towerNames.items():
            problem += createLpSum(tower.getChoiceClass(), choiceNames, choiceVariables) >= \
                tower.getHeight() + variable * \
                tower.getSpeed(), towerName

    problem = LpProblem("Lambda", LpMaximize)
    createConstraints(problem, lambdaVariable)
    problem.setObjective(lambdaVariable)
    checkPulpStatus(problem.solve(state.getSettings().getSolver()))
    lambdaOpt = lambdaVariable.value()

    freezingTowers = []
    for currentTower, towerName in towerNames.items():
        if currentTower.isFrozen():
            continue
        problem = LpProblem(towerName, LpMaximize)
        createConstraints(problem, lambdaOpt)
        problem.setObjective(
            createLpSum(currentTower.getChoiceClass(), choiceNames,
                        choiceVariables) -
            lambdaOpt * currentTower.getSpeed() - currentTower.getHeight())
        checkPulpStatus(problem.solve(state.getSettings().getSolver()))
        value = problem.objective.value()
        if not state.getSettings().isNonnegative(value):
            raise ValueError(
                str(value) + " negative while determining frozen state of " +
                repr(currentTower))
        if state.getSettings().isClose(problem.objective.value(), 0):
            freezingTowers.append(currentTower)

    return (lambdaOpt, frozenset(freezingTowers))
Example #6
0
def computeLambda(state, maximumTime=1.0):
    '''
    @type state: SSRState
    @type maximumTime: float
    '''
    towerNames = getUniqueNames(state.getTowers(), prefix="T")
    choiceNames = getUniqueNames(state.getChoices(), prefix="")
    choiceVariables = LpVariable.dicts("p", choiceNames.values(), lowBound=0.0)
    lambdaVariable = LpVariable("l", lowBound=0.0, upBound=maximumTime)

    def createConstraints(problem, variable):
        problem += lpSum(choiceVariables) <= 1, "Distribution"
        for tower, towerName in towerNames.items():
            problem += createLpSum(tower.getChoiceClass(), choiceNames, choiceVariables) >= \
                tower.getHeight() + variable * \
                tower.getSpeed(), towerName

    problem = LpProblem("Lambda", LpMaximize)
    createConstraints(problem, lambdaVariable)
    problem.setObjective(lambdaVariable)
    checkPulpStatus(problem.solve(state.getSettings().getSolver()))
    lambdaOpt = lambdaVariable.value()

    freezingTowers = []
    for currentTower, towerName in towerNames.items():
        if currentTower.isFrozen():
            continue
        problem = LpProblem(towerName, LpMaximize)
        createConstraints(problem, lambdaOpt)
        problem.setObjective(createLpSum(currentTower.getChoiceClass(), choiceNames, choiceVariables)
                             - lambdaOpt * currentTower.getSpeed() - currentTower.getHeight())
        checkPulpStatus(problem.solve(state.getSettings().getSolver()))
        value = problem.objective.value()
        if not state.getSettings().isNonnegative(value):
            raise ValueError(str(value) + " negative while determining frozen state of " +
                             repr(currentTower))
        if state.getSettings().isClose(problem.objective.value(), 0):
            freezingTowers.append(currentTower)

    return (lambdaOpt, frozenset(freezingTowers))
 def createConstraints(problem, variable):
     problem += lpSum(choiceVariables) <= 1, "Distribution"
     for tower, towerName in towerNames.items():
         problem += createLpSum(tower.getChoiceClass(), choiceNames, choiceVariables) >= \
             tower.getHeight() + variable * \
             tower.getSpeed(), towerName
Example #8
0
 def createConstraints(problem, variable):
     problem += lpSum(choiceVariables) <= 1, "Distribution"
     for tower, towerName in towerNames.items():
         problem += createLpSum(tower.getChoiceClass(), choiceNames, choiceVariables) >= \
             tower.getHeight() + variable * \
             tower.getSpeed(), towerName