This example optimizes a set of a balls to form 100 chains packed into a box. It illustrates using Monte Carlo and conjugate gradients in conjunction in a non-trivial optimization.
32 nmc = ni * nj * np * 100
49 for i
in range(0, ni):
50 for j
in range(0, nj):
53 for k
in range(0, np):
55 p.set_name(
"P" + str(i) +
" " + str(j) +
" " + str(k))
59 d.set_coordinates_are_optimized(
True)
61 movers[-1].set_was_used(
True)
65 d.set_coordinates(base)
67 d.set_coordinates_are_optimized(
True)
80 restraints.append(bbr)
91 nbl.set_pair_filters(filters)
94 mc.set_scoring_function(sf)
98 mc.set_score_moved(
True)
105 cg.set_scoring_function(sf)
108 print(r.get_name(), r.evaluate(
False))
111 for i
in range(1, nouter):
121 for j
in range(0, ninner):
123 mc.set_kt(100.0 / (3 * j + 1))
124 print(
"mc", mc.optimize((j + 1) * nmc), cg.optimize(nmc))
127 print(r.get_name(), r.evaluate(
False))