19 from __future__
import print_function
31 def evaluate_index(self, m, pair, accum):
32 price0 = Price(m.get_particle(pair[0])).get_price()
33 price1 = Price(m.get_particle(pair[1])).get_price()
34 return price0 + price1
36 def do_get_inputs(self, m, pis):
42 def __init__(self, prices):
44 IMP.domino.ParticleStates.__init__(self)
46 def load_particle_state(self, i, particle):
48 pr.set_price(self.prices[i])
50 def get_number_of_particle_states(self):
51 return len(self.prices)
57 def __init__(self, p):
58 if not self.get_is_setup(p):
59 self.setup_particle(p)
62 def setup_particle(self, p):
63 p.add_attribute(self.price_key, 0)
67 return self.particle.get_value(self.price_key)
69 def set_price(self, x):
70 self.particle.set_value(self.price_key, int(x))
72 def get_is_setup(self, p):
73 return p.has_attribute(self.price_key)
76 def get_total_price(states_table, subset, assignment):
78 for i, p
in enumerate(subset):
79 price_states = states_table.get_particle_states(p)
80 price_states.load_particle_state(assignment[i], p)
81 price = Price(p).get_price()
86 def print_assignment(states_table, subset, assignment):
87 print(
"########## solution assignment", assignment)
88 for i, p
in enumerate(subset):
89 price_states = states_table.get_particle_states(p)
90 price_states.load_particle_state(assignment[i], p)
91 price = Price(p).get_price()
92 print(p.get_name(),
"price", price)
98 prices = [100, 200, 400, 600, 800]
106 all_possible_states = PriceStates(prices)
110 for i
in range(n_girls):
115 states_table.set_particle_states(p, all_possible_states)
121 n_dresses = random.randrange(1, len(prices) + 1)
124 selection = random.sample(prices, n_dresses)
125 allowed_states_indices = [prices.index(price)
for price
in selection]
126 print(p.get_name(),
"prices selected", selection,
"indices",
127 allowed_states_indices)
129 list_states_table.set_allowed_states(p, allowed_states_indices)
130 sampler.add_subset_filter_table(list_states_table)
134 for z
in range(n_edges):
136 i = random.randrange(0, n_girls)
137 j = random.randrange(0, n_girls)
140 score = SumPricePairScore()
145 sampler.add_subset_filter_table(ft)
146 sampler.set_restraints(rs)
148 subset = states_table.get_subset()
149 solutions = sampler.get_sample_assignments(subset)
151 if len(solutions) == 0:
152 print(
"There are no solutions to the problem")
155 best_solution = solutions[0]
156 for assignment
in solutions:
157 total_price = get_total_price(states_table, subset, assignment)
158 if(total_price > most_expensive):
159 most_expensive = total_price
160 best_solution = assignment
161 print(
" There are", len(solutions),
"possible solutions")
162 print(
"=================> BEST SOLUTION <==============")
163 print_assignment(states_table, subset, best_solution)
Abstract class for scoring object(s) of type ParticleIndexPair.
Maintain an explicit list of what states each particle is allowed to have.
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
A class to store a fixed array of same-typed values.
Sample best solutions using Domino.
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
Class for storing model, its restraints, constraints, and particles.
Do not allow two particles to be in the same state.
Interface to specialized Particle types (e.g. atoms)
Basic functionality that is expected to be used by a wide variety of IMP users.
Class to handle individual particles of a Model object.
Applies a PairScore to a Pair.
Divide-and-conquer inferential optimization in discrete space.