Package expressions

Examples of expressions.FuzzyConstantExpression


            if (!varMap.containsKey(name))
                addVariable(name);
            return varMap.get(name);
        }
        else if (exp instanceof FuzzyConstantExpression) {
            FuzzyConstantExpression cstexp = (FuzzyConstantExpression) exp;
            int val = (int) (Math.round(cstexp.getValue() * totalNumberOfDegrees));
            return new IntegerConstantVariable(val);
        }
        else if (exp instanceof FuzzyUnaryExpression) {
            FuzzyUnaryExpression unexp = (FuzzyUnaryExpression) exp;
            if (unexp.getOperator() instanceof N) {
View Full Code Here


            return new Pair(new FuzzyUnaryExpression(exp1.a, new NM()), exp1.b);
        }
        else if (!Character.isDigit(head.charAt(0)))
            return new Pair(new FuzzyVariableExpression(head), startIndex + 1);
        else
            return new Pair(new FuzzyConstantExpression(Double.parseDouble(head)), startIndex + 1);
    }
View Full Code Here

        else if (p < pBinary + pUnary + pVar)
            return new FuzzyVariableExpression(variables.get(rand.nextInt(variables.size())));
        else {
            int m = (int) (1.0 / STEP_CONST);
            double val = ((double) rand.nextInt(m + 1)) / ((double) m);
            return new FuzzyConstantExpression(val);
        }
    }
View Full Code Here

  public Set<FaspConstant> getConstants() {
    return new TreeSet<FaspConstant>();
  }

  public FuzzyExpression convertToFuzzyExpression() {
    return new FuzzyConstantExpression(getValue());
  }
View Full Code Here

        for (GroundRule r : prog.getRules()) {
            if (r.getHead() instanceof GroundLiteral) {
                GroundLiteral l = (GroundLiteral) r.getHead();
                ArrayList<FuzzyExpression> args = new ArrayList<FuzzyExpression>();
                args.add(r.convertBodyExpression());
                args.add(new FuzzyConstantExpression(rho.getValue(r)));
                FuzzyExpression support = new FuzzyMultiExpression(args, r.getRuleTNorm());
                if (litMap.containsKey(l)) {
                    // Use the maximum directly in the expression associated.
                    litMap.put(l, new FuzzyBinaryExpression(litMap.get(l), support, new SM()));
                } else {
View Full Code Here

//        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);
View Full Code Here

    }

    private IntermediateResult process(FuzzyExpression exp, boolean negated) {

        if (exp instanceof FuzzyConstantExpression) {
            FuzzyConstantExpression exp1 = (FuzzyConstantExpression) exp;
            double constant = exp1.getValue();
            return new ConstantResult(negated ? 1 - constant : constant);
        }
        else if (exp instanceof FuzzyVariableExpression) {
            FuzzyVariableExpression exp1 = (FuzzyVariableExpression) exp;
            if (!negated)
                return new VariableResult(exp1.getName(), new ArrayList());
            else {
                String name = exp1.getName();
                String var = name.startsWith("neg") ? name.substring(3) : "neg" + name;
                variables.add(var);
                String[] vars = new String[2];
                vars[0] = name;
                vars[1] = var;
                double[] coeffs = new double[2];
                coeffs[0] = 1;
                coeffs[1] = 1;
                LinearInequality li1 = new LinearInequality(vars, coeffs, LpSolve.EQ, 1);
                List<DisjunctiveLinearInequality> res = new ArrayList();
                res.add(new DisjunctiveLinearInequality(li1));
                return new VariableResult(var, res);
            }
        }
        else if (exp instanceof FuzzyUnaryExpression) {
            FuzzyUnaryExpression exp1 = (FuzzyUnaryExpression) exp;
            UnaryOperator op = exp1.getOperator();
            if (op instanceof N)
                return process(exp1.getArgument(), !negated);
            else {
                System.err.println("Unary operator not supported (LinearProgrammingSolver) : " + op);
                return null;
            }
        }
        else if (exp instanceof FuzzyBinaryExpression) {
            FuzzyBinaryExpression exp1 = (FuzzyBinaryExpression) exp;
            BinaryOperator op = exp1.getOperator();
            FuzzyExpression arg1 = exp1.getArgument1();
            FuzzyExpression arg2 = exp1.getArgument2();
            List<DisjunctiveLinearInequality> res = new ArrayList();
            if (op instanceof SM) {
                IntermediateResult ir1 = process(arg1, false);
                IntermediateResult ir2 = process(arg2, false);
                if ((ir1 instanceof VariableResult) && (ir2 instanceof ConstantResult)) {
View Full Code Here

            if (!varMap.containsKey(name))
                addIntegerVariable(name, 0, numberOfDegrees);
            return varMap.get(name);
        }
        else if (exp instanceof FuzzyConstantExpression) {
            FuzzyConstantExpression cstexp = (FuzzyConstantExpression) exp;
            int val = (int) (Math.round(cstexp.getValue() * numberOfDegrees));
            return new IntegerConstantVariable(val);
        }
        else if (exp instanceof FuzzyUnaryExpression) {
            FuzzyUnaryExpression unexp = (FuzzyUnaryExpression) exp;
            if (unexp.getOperator() instanceof N) {
View Full Code Here

            if (!varMap.containsKey(name))
                addVariable(name);
            return varMap.get(name);
        }
        else if (exp instanceof FuzzyConstantExpression) {
            FuzzyConstantExpression cstexp = (FuzzyConstantExpression) exp;
            int val = (int) (Math.round(cstexp.getValue() * totalNumberOfDegrees));
            return new IntegerConstantVariable(val);
        }
        else if (exp instanceof FuzzyUnaryExpression) {
            FuzzyUnaryExpression unexp = (FuzzyUnaryExpression) exp;
            if (unexp.getOperator() instanceof N) {
View Full Code Here

      FuzzyExpression aExpr = new FuzzyVariableExpression(a.toString());
      FuzzyExpression bodyExpr;
      if (ruleMap.containsKey(a)) {
        bodyExpr = ruleMap.get(a);
      } else {
        bodyExpr = new FuzzyConstantExpression(0.0);
      }
      FuzzyExpression exp1 = new FuzzyBinaryExpression(aExpr, bodyExpr, new IW());
      FuzzyExpression exp2 = new FuzzyBinaryExpression(bodyExpr, aExpr, new IW());
      // TODO DEBUG commenting out following line is a test
      //clauseList.add(new FuzzyClause(
      //    new FuzzyLiteral(1.0, 1.0, new FuzzyBinaryExpression(exp1, exp2, new TM()))));
      // TODO DEBUG adding the following two lines is a test as well ...
      clauseList.add(new FuzzyClause(new FuzzyLiteral(1.0,1.0, exp1)));
      clauseList.add(new FuzzyClause(new FuzzyLiteral(1.0,1.0,exp2)));
      //compArgs.add(new FuzzyBinaryExpression(aExpr, bodyExpr, new IW()));
      //compArgs.add(new FuzzyBinaryExpression(bodyExpr, aExpr, new IW()));
    }

    // Add clauses for constraints (only with Lukasiewicz implicator)
    // TODO: add other implicators or something
    for (GroundRule r : getRules()) {
      if (r.getHead() instanceof LattVal) {
        Double headVal = ((LattVal) r.getHead()).getValue();
        clauseList.add(new FuzzyClause(
            new FuzzyLiteral(1.0, 1.0,
            new FuzzyBinaryExpression(r.convertBodyExpression(),
            new FuzzyConstantExpression(headVal), new IW()))));
      }
    }

    return clauseList;
View Full Code Here

TOP

Related Classes of expressions.FuzzyConstantExpression

Copyright © 2018 www.massapicom. 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.