/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package csp;
import fuzzysat.FuzzyClause;
import java.util.*;
import java.io.*;
import csp.*;
import csp.backends.*;
import csp.convertors.*;
import csp.datatypes.*;
import evaluation.RandomProblemGenerator;
import expressions.DoubleNegationEliminator;
import expressions.FuzzyConstantExpression;
import expressions.FuzzyExpression;
import fuzzysat.FuzzyLiteral;
import fuzzysat.Literal;
/**
*
* @author steven
*/
public class MinionCSPSolver {
public static String pathToMinion = "minion-0.10/bin/minion";
public static String pathToTaylor = "tailorV0.3.2/tailor.jar";
int defaultBound;
int k;
int totalNumberOfDegrees;
Map<String, Integer> specificBounds;
int timeout = 1000000;
List<FuzzyClause> clauses = new ArrayList();
DoubleNegationEliminator dnegElim = new DoubleNegationEliminator();
public MinionCSPSolver(int defaultBound, Map<String, Integer> specificBounds, int k) {
this.defaultBound = defaultBound;
this.specificBounds = specificBounds;
this.k = k;
totalNumberOfDegrees = defaultBound * k;
// System.out.println("specificBounds = " + specificBounds);
// System.out.println("defaultBound = " + defaultBound);
// System.out.println("totalNumberOfDegrees = " + totalNumberOfDegrees);
}
public Map<String, Double> getModel() {
if(clauses.size()==0)
return new HashMap();
// System.out.println("clauses = " + clauses);
FuzzyToEnumeratedIntegerConvertor ficonv = new FuzzyToEnumeratedIntegerConvertor(defaultBound,k,specificBounds);
for (FuzzyClause c : clauses)
ficonv.addFuzzyClause(c);
TailorSolver solv = new TailorSolver(pathToTaylor, pathToMinion);
solv.setTimeout(timeout);
solv.read(ficonv.convertToCSPProblem());
CSPSolution solution = solv.solve();
if (solution == null)
return null;
else
return ficonv.convertCSPSolutionToFuzzyModel(solution);
}
public void addFuzzyClause(FuzzyClause fc) {
// System.out.println("voor = " + fc);
ArrayList<Literal> newLiterals = new ArrayList<Literal>();
for (Literal l : fc.getDisjuncts()) {
FuzzyLiteral flit = (FuzzyLiteral) l;
FuzzyExpression newExp = flit.getExpression().accept(dnegElim);
newLiterals.add(new FuzzyLiteral(flit.getLowerBound(),
flit.getUpperBound(), newExp));
}
FuzzyClause fcnieuw = new FuzzyClause(newLiterals);
// System.out.println("na = " + fcnieuw);
clauses.add(fcnieuw);
}
public void setTimeout(int timeout) {
this.timeout = timeout;
}
public static void main(String [] args){
// List<FuzzyClause> clauses = RandomProblemGenerator.readConstraintsFromFile(
// new File("dataset/problem0.txt"));
List<FuzzyClause> clauses = new ArrayList();
FuzzyLiteral lit = new FuzzyLiteral(0.25,0.75,new FuzzyConstantExpression(0.5));
FuzzyClause cl = new FuzzyClause(lit);
clauses.add(cl);
MinionCSPSolver s = new MinionCSPSolver(1,new HashMap(), 4);
for(FuzzyClause fc:clauses)
s.addFuzzyClause(fc);
System.out.println(s.getModel());
}
}