/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package InitialSchedules;

import org.chocosolver.solver.Solution;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.search.limits.BacktrackCounter;
import org.chocosolver.solver.search.restart.MonotonicRestartStrategy;

import java.util.List;

/**
 *
 * @author frabe
 */
public class SolverInitialSchedules {

    private final Solver solverInitialSchedules;
    
    public SolverInitialSchedules (ModelFullTimeEmployeesInitialSchedules myModelFullTimeEmployeesInitialSchedules){
            
        this.solverInitialSchedules = myModelFullTimeEmployeesInitialSchedules.chocoModelInitialSchedules.getSolver();
        try {
            solverInitialSchedules.propagate();
        } catch (ContradictionException e) {
            System.err.println("Caught ContradictionException: " + e.getMessage());
            solverInitialSchedules.getEngine().flush();
        } catch (Exception e) {
            System.err.println("Caught Exception: " + e.getMessage());
        }
        solverInitialSchedules.setRestartOnSolutions();
        solverInitialSchedules.limitSolution(1);
        solverInitialSchedules.limitTime(1000000);
            
    }
    
    public SolverInitialSchedules (ModelPartTimeEmployeesInitialSchedules myModelPartTimeEmployeesInitialSchedules){
            
        this.solverInitialSchedules = myModelPartTimeEmployeesInitialSchedules.chocoModelInitialSchedules.getSolver();
        try {
            solverInitialSchedules.propagate();
        } catch (ContradictionException e) {
            System.err.println("Caught ContradictionException: " + e.getMessage());
            solverInitialSchedules.getEngine().flush();
        } catch (Exception e) {
            System.err.println("Caught Exception: " + e.getMessage());
        }
        solverInitialSchedules.setRestartOnSolutions();
        BacktrackCounter restartCriterion = new BacktrackCounter(myModelPartTimeEmployeesInitialSchedules.chocoModelInitialSchedules, 100000);
        solverInitialSchedules.setRestarts(restartCriterion, new MonotonicRestartStrategy(50000), 1000);
        solverInitialSchedules.limitSolution(1);
        solverInitialSchedules.limitTime(1000000);
            
    }
    
    public List<Solution> findAllSolution() {
        List<Solution> myInitialSchedulesSolutions;
        myInitialSchedulesSolutions = solverInitialSchedules.findAllSolutions();
        return myInitialSchedulesSolutions;
    }
    
    public void printStatistics(){
        solverInitialSchedules.printShortStatistics();
    }
    
}
