def solve(guide, picked_plants, width, length): """Iterates through all possible ordering of the plants. Compares the benefits of each setting of plants, and returns the highest score.""" peers = generate_peers(width, length) squares = generate_squares(width, length) patterns = {plants:True for plants in permutations(picked_plants, len(picked_plants))} planting_score, best_values, best_benefits = max( score(squares, plants, peers, guide) for plants in patterns) return set_plants(squares, best_values), best_benefits
def show_plot(): image_list = setplants.image_list() plant_count = json.loads(request.form.get('plant_counts')) length = int(json.loads(request.form.get('plot_length'))) width = int(json.loads(request.form.get('plot_width'))) guide = {} picked_plants = [] for key in plant_count: if plant_count[key] > 0: for i in range(plant_count[key]): plant = db.session.query(Plants).get(int(key)) picked_plants.append(plant.name) guide[plant.name] = {'friend':plant.friend, 'avoid':plant.avoid} solved, benefits = setplants.solve(guide, picked_plants, width, length) order = generate_squares(width, length) total_score = sum(benefits[p] for p in benefits) return render_template('/fin.html', order=order, solved=solved, benefits=benefits, image_list=image_list, length=length, width=width, box=111, total_score=total_score)