![JAR search and dependency download from the Maven repository](/logo.png)
org.chocosolver.samples.integer.SocialGolfer Maven / Gradle / Ivy
/**
* Copyright (c) 2015, Ecole des Mines de Nantes
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the .
* 4. Neither the name of the nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.chocosolver.samples.integer;
import org.chocosolver.samples.AbstractProblem;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.constraints.IntConstraintFactory;
import org.chocosolver.solver.constraints.LogicalConstraintFactory;
import org.chocosolver.solver.search.strategy.IntStrategyFactory;
import org.chocosolver.solver.variables.BoolVar;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.VariableFactory;
import org.chocosolver.util.ESat;
import org.chocosolver.util.tools.ArrayUtils;
import org.kohsuke.args4j.Option;
/**
* 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 createSolver() {
solver = new Solver("Social golfer " + g + "-" + w + "-" + s);
}
@Override
public void buildModel() {
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] = VariableFactory.boolMatrix("p_" + i, g, w, solver);
}
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