28 def evaluate(self, pair, accum):
29 price0 = Price(pair[0]).get_price()
30 price1 = Price(pair[1]).get_price()
31 return price0 + price1
33 def do_get_inputs(self, m, pis):
34 return [m.get_particle(i)
for i
in pis]
39 def __init__(self, prices):
41 IMP.domino.ParticleStates.__init__(self)
43 def load_particle_state(self, i, particle):
45 pr.set_price(self.prices[i])
47 def get_number_of_particle_states(self):
48 return len(self.prices)
54 def __init__(self, p):
55 if not self.get_is_setup(p):
56 self.setup_particle(p)
59 def setup_particle(self, p):
60 p.add_attribute(self.price_key, 0)
64 return self.particle.get_value(self.price_key)
66 def set_price(self, x):
67 self.particle.set_value(self.price_key, int(x))
69 def get_is_setup(self, p):
70 return p.has_attribute(self.price_key)
73 def get_total_price(states_table, subset, assignment):
75 for i, p
in enumerate(subset):
76 price_states = states_table.get_particle_states(p)
77 price_states.load_particle_state(assignment[i], p)
78 price = Price(p).get_price()
83 def print_assignment(states_table, subset, assignment):
85 print "########## solution assignment", assignment
86 for i, p
in enumerate(subset):
87 price_states = states_table.get_particle_states(p)
88 price_states.load_particle_state(assignment[i], p)
89 price = Price(p).get_price()
90 print p.get_name(),
"price", price
96 prices = [100, 200, 400, 600, 800]
104 all_possible_states = PriceStates(prices)
108 for i
in range(n_girls):
113 states_table.set_particle_states(p, all_possible_states)
119 n_dresses = random.randrange(1, len(prices) + 1)
122 selection = random.sample(prices, n_dresses)
123 allowed_states_indices = [prices.index(price)
for price
in selection]
124 print p.get_name(),
"prices selected", selection,
"indices", allowed_states_indices
126 list_states_table.set_allowed_states(p, allowed_states_indices)
127 sampler.add_subset_filter_table(list_states_table)
130 for z
in xrange(n_edges):
132 i = random.randrange(0, n_girls)
133 j = random.randrange(0, n_girls)
136 score = SumPricePairScore()
138 model.add_restraint(r)
142 sampler.add_subset_filter_table(ft)
144 subset = states_table.get_subset()
145 solutions = sampler.get_sample_assignments(subset)
147 if len(solutions) == 0:
148 print "There are no solutions to the problem"
151 best_solution = solutions[0]
152 for assignment
in solutions:
153 total_price = get_total_price(states_table, subset, assignment)
154 if(total_price > most_expensive):
155 most_expensive = total_price
156 best_solution = assignment
157 print " There are", len(solutions),
"possible solutions"
158 print "=================> BEST SOLUTION <=============="
159 print_assignment(states_table, subset, best_solution)
Maintain an explicit list of what states each particle is allowed to have.
Sample best solutions using Domino.
A class to store an fixed array of same-typed values.
Do not allow two particles to be in the same state.
Abstract class for scoring object(s) of type ParticlePair.
Class to handle individual model particles.
Basic functionality that is expected to be used by a wide variety of IMP users.
Applies a PairScore to a Pair.
Divide-and-conquer inferential optimization in discrete space.
Class for storing model, its restraints, constraints, and particles.