30 def evaluate_index(self, m, pair, accum):
31 price0 = Price(m.get_particle(pair[0])).get_price()
32 price1 = Price(m.get_particle(pair[1])).get_price()
33 return price0 + price1
35 def do_get_inputs(self, m, pis):
41 def __init__(self, prices):
43 IMP.domino.ParticleStates.__init__(self)
45 def load_particle_state(self, i, particle):
47 pr.set_price(self.prices[i])
49 def get_number_of_particle_states(self):
50 return len(self.prices)
56 def __init__(self, p):
57 if not self.get_is_setup(p):
58 self.setup_particle(p)
61 def setup_particle(self, p):
62 p.add_attribute(self.price_key, 0)
66 return self.particle.get_value(self.price_key)
68 def set_price(self, x):
69 self.particle.set_value(self.price_key, int(x))
71 def get_is_setup(self, p):
72 return p.has_attribute(self.price_key)
75 def get_total_price(states_table, subset, assignment):
77 for i, p
in enumerate(subset):
78 price_states = states_table.get_particle_states(p)
79 price_states.load_particle_state(assignment[i], p)
80 price = Price(p).get_price()
85 def print_assignment(states_table, subset, assignment):
86 print(
"########## solution assignment", assignment)
87 for i, p
in enumerate(subset):
88 price_states = states_table.get_particle_states(p)
89 price_states.load_particle_state(assignment[i], p)
90 price = Price(p).get_price()
91 print(p.get_name(),
"price", price)
97 prices = [100, 200, 400, 600, 800]
105 all_possible_states = PriceStates(prices)
109 for i
in range(n_girls):
114 states_table.set_particle_states(p, all_possible_states)
120 n_dresses = random.randrange(1, len(prices) + 1)
123 selection = random.sample(prices, n_dresses)
124 allowed_states_indices = [prices.index(price)
for price
in selection]
125 print(p.get_name(),
"prices selected", selection,
"indices",
126 allowed_states_indices)
128 list_states_table.set_allowed_states(p, allowed_states_indices)
129 sampler.add_subset_filter_table(list_states_table)
133 for z
in range(n_edges):
135 i = random.randrange(0, n_girls)
136 j = random.randrange(0, n_girls)
139 score = SumPricePairScore()
144 sampler.add_subset_filter_table(ft)
145 sampler.set_restraints(rs)
147 subset = states_table.get_subset()
148 solutions = sampler.get_sample_assignments(subset)
150 if len(solutions) == 0:
151 print(
"There are no solutions to the problem")
154 best_solution = solutions[0]
155 for assignment
in solutions:
156 total_price = get_total_price(states_table, subset, assignment)
157 if(total_price > most_expensive):
158 most_expensive = total_price
159 best_solution = assignment
160 print(
" There are", len(solutions),
"possible solutions")
161 print(
"=================> BEST SOLUTION <==============")
162 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.