All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.chocosolver.examples.integer.SocialGolfer Maven / Gradle / Ivy

/*
 * This file is part of examples, http://choco-solver.org/
 *
 * Copyright (c) 2021, IMT Atlantique. All rights reserved.
 *
 * Licensed under the BSD 4-clause license.
 *
 * See LICENSE file in the project root for full license information.
 */
package org.chocosolver.examples.integer;

import org.chocosolver.examples.AbstractProblem;
import org.chocosolver.solver.Model;
import org.chocosolver.solver.variables.BoolVar;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.util.ESat;
import org.kohsuke.args4j.Option;

import static org.chocosolver.solver.search.strategy.Search.inputOrderUBSearch;
import static org.chocosolver.util.tools.ArrayUtils.flatten;

/**
 * CSPLib prob010:
* "The coordinator of a local golf club has come to you with the following problem. * In her club, there are 32 social golfers, each of whom play golf once a week, * and always in groups of 4. * She would like you to come up with a schedule of play for these golfers, * to last as many weeks as possible, such that * no golfer plays in the same group as any other golfer on more than one occasion. *

* The problem can easily be generalized to that of scheduling * m groups of * n golfers over * p weeks, * such that no golfer plays in the same group as any other golfer twice * (i.e. maximum socialisation is achieved) * " *
* * @author Charles Prud'homme * @since 19/08/11 */ public class SocialGolfer extends AbstractProblem { // parameters g-w-s: // 3-5-2, 3-4-3, 4-7-2, 4-4-3, 5-7-3 // SPORT SCHEDULING: s=2, w = g - 1 @Option(name = "-g", aliases = "--group", usage = "Number of groups.", required = false) int g = 4; @Option(name = "-w", aliases = "--week", usage = "Number of weeks.", required = false) int w = 4; @Option(name = "-s", aliases = "--player", usage = "Number of players per group.", required = false) int s = 3; BoolVar[][][] P, M; @Override public void buildModel() { model = new Model(); int p = g * s; // number of players P = new BoolVar[p][g][w]; // p plays in group g in week w for (int i = 0; i < p; i++) { P[i] = model.boolVarMatrix("p_" + i, g, w); } M = new BoolVar[p][p][w]; // i meets j in week w (i 0) { st.append(k).append(", "); } } st.append("\n"); } st.append("\n"); } } else { st.append("\tINFEASIBLE"); } System.out.println(st.toString()); } public static void main(String[] args) { new SocialGolfer().execute(args); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy