Exemple #1
0
    def __init__(self, object_set):
        print(object_set.num_blocks())
        instance_name = 'hbw-num-blocks-%s-num-cyls-%s' % (
            object_set.num_blocks(), object_set.num_cylinders())
        Task.__init__(self, 'Hydraulic-BlocksWorld', instance_name)
        self.objects = object_set

        self.block_position_value_names = [
            on_block(k) for k in xrange(0, self.objects.num_blocks())
        ]
        self.block_position_value_names += [
            'on_piston'
        ]  #on_cylinder_piston(k) for k in xrange(0, self.objects.num_cylinders()) ]
        self.block_position_value_names += ['hand']
        self.block_position_values = {
            name: k
            for k, name in enumerate(self.block_position_value_names)
        }

        self.block_container_value_names = [
            in_cylinder(k) for k in xrange(0, self.objects.num_cylinders())
        ] + ['none']
        self.block_container_values = {
            name: k
            for k, name in enumerate(self.block_container_value_names)
        }

        self.create_vars(self.objects.num_blocks(),
                         self.objects.num_cylinders())
Exemple #2
0
	def __init__( self, counters, max_value ) :
		Task.__init__( self, 'Counters', 'Num-Counters-{0}-Max-Value-{1}'.format( len(counters), max_value ) )
		self.counters = counters
		self.max_value = int(max_value)
		self.counter_values = []
		self.create_vars()
		self.create_actions()
Exemple #3
0
 def __init__(self, object_set):
     print(object_set.num_blocks())
     instance_name = 'hbw-num-blocks-%s-num-cyls-%s' % (
         object_set.num_blocks(), object_set.num_cylinders())
     Task.__init__(self, 'Hydraulic-BlocksWorld', instance_name)
     self.objects = object_set
     self.create_vars(self.objects.num_blocks(),
                      self.objects.num_cylinders())
Exemple #4
0
 def __init__(self, counters, max_value):
     Task.__init__(
         self, 'Counters',
         'Num-Counters-{0}-Max-Value-{1}'.format(len(counters), max_value))
     self.counters = counters
     self.max_value = int(max_value)
     self.counter_values = {
         c: {k: None
             for k in xrange(0, self.max_value)}
         for c in self.counters
     }
     self.create_vars()
     self.create_actions()
 def __init__(self, network, sdac=None):
     Task.__init__(self, 'SGT_PSR_UG', 'SGT_PSR_UG_NETWORK')
     self.network = network
     self.network.find_total_load()
     self.plan_end_var = None
     self.create_vars()
     self.conditional_costs = []
     self.sdac_type = sdac
     if sdac == "Valuation":
         self.create_conditional_costs()
     elif sdac == "Objective":
         self.objective_function = "PSRObjective"
     self.create_actions()
Exemple #6
0
 def __init__(self, network, sdac=None):
     Task.__init__(self, 'SGT_PSR', 'SGT_PSR_NETWORK')
     self.network = network
     self.network.find_total_load()
     print("Total load:", self.network.total_load)
     self.create_vars()
     self.objective_function = None
     self.conditional_costs = []
     if sdac == "Valuation":
         self.create_conditional_costs()
     elif sdac == "Objective":
         self.objective_function = "PSRObjective"
     self.create_actions()
Exemple #7
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)
Exemple #8
0
 def __init__(self, name, dm, locations, demand, vehicles):
     instance_name = name
     Task.__init__(self, 'Linehaul', instance_name)
     # list of location names, depot is locations[0]:
     self.locations = locations
     self.distance_matrix = dm
     # demand[l] = (qc, qa) means the total demand for
     # chilled (ambient) goods at location l is qc (qa).
     self.demand = demand
     # vehicles: list of tuples (type, pkc, cap, chilled),
     # where: pkc = per-kilometer cost, cap = capactiy,
     # chilled = True/False
     self.vehicles = []
     self.vehicle_type = dict()
     for (vtype, count, pkc, cap, chilled) in vehicles:
         for i in range(count):
             vname = "{0}{1}".format(vtype, i)
             self.vehicles.append((vname, pkc, cap, chilled))
             self.vehicle_type[vname] = vtype
     self.create_vars()
     self.create_actions()
Exemple #9
0
 def __init__(self, power_network):
     Task.__init__(self, 'Two-End Line PSR', power_network.name)
     self.network = power_network
     self.create_vars()
     self.create_actions()
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)
Exemple #11
0
 def __init__(self, network):
     Task.__init__(self, 'SGT_PSR', 'SGT_PSR_NETWORK')
     self.network = network
     self.create_vars()
     self.create_actions()