/*
 * Copyright 2002, 2003, 2004, 2005 - <A href="http://www.koalog.com">Koalog</A>
 */
package com.koalog.jcs.examples;

import org.apache.log4j.Category;
import com.koalog.jcs.variable.IntegerVariable;
import com.koalog.jcs.solver.DefaultFFSolver;

/**
 * A solver for the round robin problem.
 *
 @author Yan Georget
 */
public class RoundRobinSolver extends DefaultFFSolver {
    //------------------------------------------------------------------------
    // STATIC PROPERTIES
    //------------------------------------------------------------------------
    private static Category cat = Category.getInstance(RoundRobinSolver.class);

    //------------------------------------------------------------------------
    // CONSTRUCTORS
    //------------------------------------------------------------------------
    /**
     * Sole constructor.
     @param p the problem
     */
    public RoundRobinSolver(RoundRobinProblem p) {
        super(p);
    }
    
    //------------------------------------------------------------------------
    // METHODS
    //------------------------------------------------------------------------
    /** @see com.koalog.jcs.solver.BaseSolver */
    public void solutionFound() {
        super.solutionFound();
        // improved display
        int n = ((RoundRobinProblem)problem).n;
        IntegerVariable[] variables = 
            (IntegerVariable[]) problem.getVariables();
        for (int p=0; p<n/2; p++) {
            StringBuffer buf = new StringBuffer();
            for (int w=0; w<n-1; w++) {
                int val = variables[w+p*(n-1)].getMin();
                buf.append(val/n);
                buf.append("-");
                buf.append(val%n);
                buf.append(" ");
            }
            cat.info(buf);
        }
    }
}