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

org.chocosolver.examples.nqueen.NQueenGlobal 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.nqueen;


import org.chocosolver.solver.Model;
import org.chocosolver.solver.variables.IntVar;

import static org.chocosolver.solver.search.strategy.Search.minDomLBSearch;

/**
 * 
* * @author Charles Prud'homme * @since 31/03/11 */ public class NQueenGlobal extends AbstractNQueen { @Override public void buildModel() { model = new Model("NQueen"); vars = new IntVar[n]; IntVar[] diag1 = new IntVar[n]; IntVar[] diag2 = new IntVar[n]; for (int i = 0; i < n; i++) { vars[i] = model.intVar("Q_" + i, 1, n, false); diag1[i] = model.intOffsetView(vars[i], i); diag2[i] = model.intOffsetView(vars[i], -i); } model.allDifferent(vars, "BC").post(); model.allDifferent(diag1, "BC").post(); model.allDifferent(diag2, "BC").post(); } @Override public void configureSearch() { model.getSolver().setSearch(minDomLBSearch(vars)); } public static void main(String[] args) { new NQueenGlobal().execute(args); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy