/* * Copyright 2002, 2003, 2004, 2005 - Koalog */ package com.koalog.jcs.examples; import org.apache.log4j.PropertyConfigurator; import com.koalog.util.matrix.SquareMatrix; import com.koalog.jcs.variable.IntegerVariable; import com.koalog.jcs.constraint.BaseProblem; import com.koalog.jcs.constraint.arithmetic.Less; import com.koalog.jcs.constraint.arithmetic.ConstantSum; import com.koalog.jcs.constraint.arithmetic.AllDifferent; /** * This is the famous magic square problem. * It consists in finding n*n matrix such that: * * @author Yan Georget */ public class MagicSquareProblem extends BaseProblem { //------------------------------------------------------------------------ // PROPERTIES //------------------------------------------------------------------------ IntegerVariable[] elements; IntegerVariable[] firstDiagonal; IntegerVariable[] secondDiagonal; //------------------------------------------------------------------------ // CONSTRUCTORS //------------------------------------------------------------------------ /** * Sole constructor. * @param n the size of the square */ public MagicSquareProblem(int n) { super(); int m = (n*n-1)*n/2; elements = new IntegerVariable[n*n]; for (int i=0; i