Package fuzzysat

Source Code of fuzzysat.IncompleteMinionSolver

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fuzzysat;

import csp.ChocoSolver;
import csp.EnumeratedChocoSolver;
import csp.MinionCSPSolver;
import finiteReduction.DomainFinder;
import finiteReduction.FiniteReductionConfig;
import java.util.*;

/**
*
* @author steven
*/
public class IncompleteMinionSolver implements FuzzySATSolver {

    static Random rand = new Random();
    int maxDegrees;
    int k;
    List<FuzzyClause> constraints;
    Map<String, Double> trivialAssignments;
    long timeout = 1000;
    long startTime = -1;

    public IncompleteMinionSolver(List<FuzzyClause> constraints) {
        this(constraints, 10);
    }

    /*
     *  the number of truth degrees that will be tried by the algorithm is k, 2*k, ..., maxDegrees*k
     */
    public IncompleteMinionSolver(List<FuzzyClause> constraints, int k) {
        this.k = k;
        this.maxDegrees = maxDegrees;
        this.constraints = constraints;
        trivialAssignments = new HashMap();

       startTime = System.currentTimeMillis();
//        System.out.println("Start preprocessing");
      
//       System.out.println("Constraints voor = " + constraints);
        if (FiniteReductionConfig.optimizeClauses) {
            boolean changed = true;
            while (changed) {
//                System.out.println("...");
                DomainFinder.simplify(constraints);
//                System.out.println("Constraints tussen = " + constraints);
                changed = DomainFinder.eliminateTriviallySatisfiableClauses(constraints, trivialAssignments);
            }
        }
//       System.out.println("Constraints na = " + constraints);
    }

    public Map<String, Double> findFuzzyModel() {
        for (int numberOfDegrees = 1;!timesUp(); numberOfDegrees++) {
            System.out.println("number of degrees = " + numberOfDegrees);
            MinionCSPSolver solv = new MinionCSPSolver(numberOfDegrees,new HashMap(),k);
            for (FuzzyClause fc : constraints) {
//                System.out.println(" constraint added: " +fc);
                solv.addFuzzyClause(fc);
            }
            if (timeout >= 0)
                solv.setTimeout((int) timeout);
            Map<String, Double> model = solv.getModel();
           
          
//            if (!trivialAssignments.isEmpty()) {
//                if (model == null) {
//                    model = new HashMap<String, Double>();
//                }
//                model.putAll(trivialAssignments);
//                return model;
//            }
           
            if (model!=null) {       
//                System.out.println("model = " + model);
//                System.out.println("trivialAssignments = " + trivialAssignments);
                model.putAll(trivialAssignments);
//                     System.out.println("model = " + model);
                return model;
            }
        }
        return null;
    }

    public void setTimeout(long l) {
        timeout = l;
    }

    private boolean timesUp() {
        if (timeout < 0 || startTime < 0)
            return false;
        long time = System.currentTimeMillis() - startTime;
//        System.out.println("time = " +  time);
        return (time > timeout * 1000);
    }
}
TOP

Related Classes of fuzzysat.IncompleteMinionSolver

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.