Package expressions

Examples of expressions.FuzzyBinaryExpression


        FuzzyUnaryExpression fu = (FuzzyUnaryExpression) exp;
        return fu.getArgument();
    }

    public Pair<FuzzyExpression, FuzzyExpression> getBinaryArgument(FuzzyExpression exp) {
        FuzzyBinaryExpression fu = (FuzzyBinaryExpression) exp;
        return new Pair(fu.getArgument1(), fu.getArgument2());
    }
View Full Code Here


                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

            this.name = name;
        }
    }

    public static void main(String[] args) {
        FuzzyExpression exp1 = new FuzzyBinaryExpression(new FuzzyVariableExpression("a"), new FuzzyVariableExpression("b"), new TW());
        FuzzyExpression exp2 = new FuzzyUnaryExpression(new FuzzyVariableExpression("c"), new N());
        FuzzyExpression exp = new FuzzyBinaryExpression(exp1, exp2, new TW());
        FuzzyLiteral lit = new FuzzyLiteral(0.2, 0.4, exp);
        FuzzyClause cl = new FuzzyClause(lit);
        List<FuzzyClause> constraints = new ArrayList();
        constraints.add(cl);
        LinearProgrammingSolver solver = new LinearProgrammingSolver(constraints);
View Full Code Here

            }
            else
                throw new UnsupportedOperationException();
        }
        else if (exp instanceof FuzzyBinaryExpression) {
            FuzzyBinaryExpression binexp = (FuzzyBinaryExpression) exp;
            if (binexp.getOperator() instanceof TW) {
                IntegerExpressionVariable var1 = getExpression(binexp.getArgument1());
                IntegerExpressionVariable var2 = getExpression(binexp.getArgument2());
                return max(new IntegerConstantVariable(0), plus(var1, plus(var2, -numberOfDegrees)));
            }
            else if(binexp.getOperator() instanceof SM){
                IntegerExpressionVariable var1 = getExpression(binexp.getArgument1());
                IntegerExpressionVariable var2 = getExpression(binexp.getArgument2());
                return max(var1,var2);
            }
            else
                throw new UnsupportedOperationException();
        }
View Full Code Here

        }
        throw new UnsupportedOperationException();
    }

    public static void main(String[] args) {
        FuzzyBinaryExpression exp1 = new FuzzyBinaryExpression(new FuzzyVariableExpression("x"),
                                                               new FuzzyVariableExpression("y"), new TW());
        FuzzyBinaryExpression exp2 = new FuzzyBinaryExpression(exp1, new FuzzyVariableExpression("z"), new SW());
//        FuzzyExpression exp1 = new FuzzyVariableExpression("x");
        FuzzyClause fc1 = new FuzzyClause(new FuzzyLiteral(0.7, 0.7, exp1));
        FuzzyClause fc2 = new FuzzyClause(new FuzzyLiteral(0.5, 0.9, new FuzzyVariableExpression("y")));
        FuzzyClause fc3 = new FuzzyClause(new FuzzyLiteral(0.2, 0.4, new FuzzyVariableExpression("y")));
        ChocoSolver solver = new ChocoSolver(10);
View Full Code Here

            }
            else
                throw new UnsupportedOperationException();
        }
        else if (exp instanceof FuzzyBinaryExpression) {
            FuzzyBinaryExpression binexp = (FuzzyBinaryExpression) exp;
            if (binexp.getOperator() instanceof TW) {
                IntegerExpressionVariable var1 = getExpression(binexp.getArgument1());
                IntegerExpressionVariable var2 = getExpression(binexp.getArgument2());
                return max(new IntegerConstantVariable(0), plus(var1, plus(var2, -totalNumberOfDegrees)));
            }
            else if (binexp.getOperator() instanceof SM) {
                IntegerExpressionVariable var1 = getExpression(binexp.getArgument1());
                IntegerExpressionVariable var2 = getExpression(binexp.getArgument2());
                return max(var1, var2);
            }
            else
                throw new UnsupportedOperationException();
        }
View Full Code Here

        }
        throw new UnsupportedOperationException();
    }

    public static void main(String[] args) {
        FuzzyBinaryExpression exp1 = new FuzzyBinaryExpression(new FuzzyVariableExpression("x"),
                                                               new FuzzyVariableExpression("y"), new TW());
        FuzzyBinaryExpression exp2 = new FuzzyBinaryExpression(exp1, new FuzzyVariableExpression("z"), new SW());
//        FuzzyExpression exp1 = new FuzzyVariableExpression("x");
        FuzzyClause fc1 = new FuzzyClause(new FuzzyLiteral(0.7, 0.7, exp1));
        FuzzyClause fc2 = new FuzzyClause(new FuzzyLiteral(0.5, 0.9, new FuzzyVariableExpression("y")));
        FuzzyClause fc3 = new FuzzyClause(new FuzzyLiteral(0.2, 0.4, new FuzzyVariableExpression("y")));
        ChocoSolver solver = new ChocoSolver(10);
View Full Code Here

    for (GroundLiteral a : getHerbrandBase()) {
      for (GroundRule r : getRules()) {
        if (r.getHead().equals(a)) {
          if (ruleMap.containsKey(a)) {
            FuzzyExpression expr = ruleMap.get(a);
            ruleMap.put(a, new FuzzyBinaryExpression(r.convertBodyExpression(), expr, new SM()));
          } else {
            ruleMap.put(a, r.convertBodyExpression());
          }
        }
      }
    }

    for (GroundLiteral a : getHerbrandBase()) {
      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


        if (ruleMap.containsKey(l)) {
          // Add the body completion of the new rule to the body completion of the other rules
          // with this literal in the head using the minimum
          ruleMap.put(l, new FuzzyBinaryExpression(ruleMap.get(l), ruleBodyCompletion, new TM()));


        } else {
          // Add the body completion
          ruleMap.put(l, ruleBodyCompletion);


        }
      }
    }

    // Now create the fuzzy literals corresponding to each fasp literal:
    // These are of the form a = (B(r_1) /\_{r_1} r_1) /\_m ... /\_m (B(r_n) /\_{r_n} r_n)
    // such that H(r_i) = a for i = 1..n, hence we add them as two implications.
    for (GroundLiteral l : ruleMap.keySet()) {
      FuzzyExpression litExp = l.convertToFuzzyExpression();
      FuzzyExpression bodyExp = ruleMap.get(l);
      // Add the first implication of the equivalence
      literalList.add(new FuzzyLiteral(1.0, 1.0, new FuzzyBinaryExpression(litExp, bodyExp, new IW())));
      // The second implication of the equivalence
      literalList.add(new FuzzyLiteral(1.0, 1.0, new FuzzyBinaryExpression(bodyExp, litExp, new IW())));


    } // Finally add l = 0 for each non-naf literal occurring nowhere in a rule head.
    // TODO: untested!
    for (GroundLiteral l : getLiterals()) {
      if (l.isNaf()) {
        l = new GroundLiteral(l.getPredicate(), l.isNegated(), false, null);
      }


      if (!ruleMap.containsKey(l)) // We'll add IW(l,0) = 1, which is equivalent to l = 0 as IW(l,0) = 1-l
      {
        literalList.add(new FuzzyLiteral(1.0, 1.0, new FuzzyBinaryExpression(
            l.convertToFuzzyExpression(), new FuzzyConstantExpression(0), new IW())));
      }


    }
View Full Code Here

    for (GroundRule r : rMinus) {
      consList.add(r.convertBodyExpression());
    }
    FuzzyExpression cons = new FuzzyMultiExpression(consList, new SM());
    return new FuzzyClause(
        new FuzzyLiteral(1.0, 1.0, new FuzzyBinaryExpression(ant, cons, new IW())));
  }
View Full Code Here

TOP

Related Classes of expressions.FuzzyBinaryExpression

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.