Esempio n. 1
0
def project_primary_over_vars(task, G, variable_set):

    variable_map = {}
    inv_variable_map = {}
    action_map = {}
    inv_action_map = {}

    # create projected primary task
    projected_primary = Task(task.domain_name, task.instance_name)

    # re-map primary task variables
    for new_index, old_index in enumerate(variable_set):
        variable_map[old_index] = new_index
        inv_variable_map[new_index] = old_index
        x = task.state_vars[old_index]
        projected_primary.create_state_var(x.name, x.domain, x.default_value)

    # re-map planning task actions
    for old_index, action in enumerate(task.actions):
        new_index = len(projected_primary.actions)
        new_primary_precs = []
        for x, v in action.prim_precs:
            if x not in variable_map:
                continue
            new_primary_precs.append((variable_map[x], v))
        new_effect = []
        for x, v in action.effect:
            if x not in variable_map:
                continue
            new_effect.append((variable_map[x], v))
        if len(new_effect) == 0:
            continue
        projected_primary.actions.append(
            Action(action.name, new_primary_precs, action.sec_precs,
                   new_effect, action.cost))
        action_map[old_index] = new_index
        inv_action_map[new_index] = old_index

    #print( 'Projected task created' )
    #projected_primary.print_statistics( sys.stdout )

    projected_G = []
    for x, v in G:
        if x not in variable_map: continue
        projected_G.append((variable_map[x], v))

    return projected_primary, projected_G, (variable_map,
                                            inv_variable_map), (action_map,
                                                                inv_action_map)
Esempio n. 2
0
def project_primary_over_vars(task, G, variable_set):

    variable_map = {}
    inv_variable_map = {}
    action_map = {}
    inv_action_map = {}

    # create projected primary task
    projected_primary = Task(task.domain_name, task.instance_name)

    #print("Projecting primary")

    # re-map primary task variables
    for new_index, old_index in enumerate(variable_set):
        variable_map[old_index] = new_index
        inv_variable_map[new_index] = old_index
        x = task.state_vars[old_index]
        projected_primary.create_state_var(x.name, x.domain, x.default_value)
#print("Name: ", x.name, " Old index: ",old_index , " New index", new_index)

#print("Done with primary. Actions now.")

    # re-map planning task actions
    for old_index, action in enumerate(task.actions):
        new_index = len(projected_primary.actions)
        new_primary_precs = []
        for x, v in action.prim_precs:
            if x not in variable_map:
                continue
            new_primary_precs.append((variable_map[x], v))
        new_effect = []
        for x, v in action.effect:
            if x not in variable_map:
                continue
            new_effect.append((variable_map[x], v))
        if len(new_effect) == 0:
            continue
        new_conditional_costs = []
        for cc in action.conditional_costs:
            new_primary_condition = []
            for x, v in cc.primary_conditions:
                if x not in variable_map:
                    print("x not in variable map:", x)
                    continue
                new_primary_condition.append((variable_map[x], v))
            new_secondary_condition = []
            if len(new_primary_condition) == 0 and len(
                    new_secondary_condition) == 0:
                print("No primary or secondary conditions")
                continue
            new_conditional_costs.append(
                ConditionalCost(primary_condition=new_primary_condition,
                                secondary_condition=new_secondary_condition,
                                ccost=cc.ccost))

#print("variable_map is ", variable_map)
#print("conditional_costs are ")
#for cc in action.conditional_costs :
#print("conditions :")
#for x,v in cc.primary_conditions :
#print(x,v)
#print("cost ", cc.ccost)
#print("new conditional costs are : ")
#for ncc in new_conditional_costs :
#print("conditions :")
#for x,v in ncc.primary_conditions :
#    print(x,v)
#print("cost ", cc.ccost)
        projected_primary.actions.append(
            Action(action.name,
                   new_primary_precs,
                   action.sec_precs,
                   new_effect,
                   action.cost,
                   conditional_costs=new_conditional_costs,
                   objective_function=action.objective_function,
                   of_vname=action.of_varname))
        #print("Addng action: ", action.name, " New primary precs: ", new_primary_precs, " Effects: ", new_effect)
        action_map[old_index] = new_index
        inv_action_map[new_index] = old_index

    projected_G = []
    for x, v in G:
        if x not in variable_map: continue
        projected_G.append((variable_map[x], v))

    return projected_primary, projected_G, (variable_map,
                                            inv_variable_map), (action_map,
                                                                inv_action_map)