Package fasp.datatypes

Examples of fasp.datatypes.GroundLiteral


    ArrayList<FaspConstant> pargs = new ArrayList<FaspConstant>();
    for (FaspConstant c : args) {
      pargs.add(c);
    }
    GroundPredicate p = new GroundPredicate(name, pargs);
    return new GroundLiteral(p, false, naf, nafOp);
  }
View Full Code Here


        solution.putAll(trivialAssignments);
        checkModel(clauses, solution);
        printSolution(solution);
        Map<GroundLiteral, Double> interp = new HashMap<GroundLiteral, Double>();
        for (String s : solution.keySet()) {
          GroundLiteral lit = parseLiteral(s);
          interp.put(lit, solution.get(s));
        }
        i = new FaspInterpretation(interp);
        if (prog.isAnswerSet(i)) {
          anssetfound = true;
View Full Code Here

    for (FaspConstant a : atm) {
      for (FaspConstant t1 : town) {
        for (FaspConstant t2 : town) {
          // Different to the TPLP paper:
          if (!t1.equals(t2)) {
            GroundLiteral head = createRegLiteral("loc", a, t1, t2);
            boolVars.put(head.toString(), 1);
          }
        }
      }
    }
    for (FaspConstant t1 : town) {
View Full Code Here

    // Distance and connection facts
    for (FaspConstant t1 : town) {
      for (FaspConstant t2 : town) {
        if (distances.containsKey(new Pair<String, String>(t1.getName(), t2.getName()))) {
          GroundLiteral headd = createRegLiteral("near", t1, t2);
          GroundLiteral headc = createRegLiteral("conn", t1, t2);
          GroundRule factd = createRegularRule(headd, new TW(),
              new LattVal(distances.get(new Pair<String, String>(t1.getName(), t2.getName()))));
          GroundRule factc = createRegularRule(headc, new TW(), new LattVal(1.0));
          rules.add(factd);
          rules.add(factc);
        }
      }
    }

    // gloc rule
    for (FaspConstant a : atm) {
      for (FaspConstant t1 : town) {
        for (FaspConstant t2 : town) {
          // Different to the TPLP paper:
          if (!t1.equals(t2)) {
            GroundLiteral head = createRegLiteral("loc", a, t1, t2);

            GroundLiteral bodyl = createRegLiteral("conn", t1, t2);
            ArrayList<FaspFuzzyExpression> body = new ArrayList<FaspFuzzyExpression>();
            body.add(bodyl);

            for (FaspConstant tt1 : town) {
              for (FaspConstant tt2 : town) {
                if (!(((t1.equals(tt1)) && (t2.equals(tt2))) || ((t1.equals(tt2))
                    || (t2.equals(tt1))))
                    && (!tt1.equals(tt2))) {
                  GroundLiteral betaLit = createLiteral("loc", true, new NM(), a, tt1, tt2);
                  body.add(betaLit);
                }
              }
            }

            GroundRule locRule = new GroundRegularRule(head, body, new TW());
            rules.add(locRule);
          }
        }
      }
    }

    // gnear rule
    for (FaspConstant a : atm) {
      for (FaspConstant t : town) {
        // Why doesn't Java just support new ArrayList<FaspConstant>({a,t}) ?
        GroundLiteral head = createLiteral("locNear", false, null, a, t);
        GroundLiteral bodyElt = createLiteral("locNear2", true, new N(), a, t);
        GroundRule gnear = createRegularRule(head, new TW(), bodyElt);
        rules.add(gnear);
      }
    }

    // gnear' rule
    for (FaspConstant a : atm) {
      for (FaspConstant t1 : town) {
        GroundLiteral head = createLiteral("locNear2", false, null, a, t1);
        for (FaspConstant t2 : town) {
          GroundLiteral b1 = createRegLiteral("loc", a, t1, t2);
          GroundLiteral b2 = createNafLiteral("near", new N(), t1, t2);
          GroundLiteral b3 = createRegLiteral("locNear", a, t2);
          GroundRule gnearP = createRegularRule(head, new TW(), b1, b2, b3);
          rules.add(gnearP);
        }
      }
    }

    // nearr rule
    for (FaspConstant t1 : town) {
      for (FaspConstant t2 : town) {
        GroundLiteral head = createRegLiteral("near", t1, t2);
        for (FaspConstant t3 : town) {
          GroundLiteral b1 = createRegLiteral("conn", t1, t3);
          GroundLiteral b2 = createRegLiteral("near", t1, t3);
          GroundLiteral b3 = createRegLiteral("near", t3, t2);
          GroundRule nearr = createRegularRule(head, new TW(), b1, b2, b3);
          rules.add(nearr);
        }
      }
    }

    // locr rule
    for (FaspConstant a : atm) {
      for (FaspConstant t1 : town) {
        for (FaspConstant t2 : town) {
          // Small optimization
          if (!t1.equals(t2)) {
            GroundLiteral head = createRegLiteral("loc", a, t1, t2);
            GroundLiteral body = createRegLiteral("loc", a, t2, t1);
            GroundRule locr = createRegularRule(head, new TW(), body);
            rules.add(locr);
          }
        }
      }
    }

    // atmr rule
    for (FaspConstant a : atm) {
      for (FaspConstant t : town) {
        //GroundLiteral head = createRegLiteral("isNear", a, t);
        GroundLiteral head = createRegLiteral("atmNear", a, t);
        for (FaspConstant t1 : town) {
          for (FaspConstant t2 : town) {
            GroundLiteral b1 = createRegLiteral("loc", a, t1, t2);
            GroundLiteral b2 = createRegLiteral("locNear", a, t1);
            GroundLiteral b3 = createRegLiteral("near", t, t1);
            GroundRule atmr = createRegularRule(head, new TW(), b1, b2, b3);
            rules.add(atmr);
          }
        }
      }
    }

    // nearestAtm rule
    for (FaspConstant t : town) {
      GroundLiteral head = createRegLiteral("nearestAtm", t);
      for (FaspConstant a : atm) {
        GroundLiteral b = createRegLiteral("atmNear", a, t);
        GroundRule nearestAtm = createRegularRule(head, new TW(), b);
        rules.add(nearestAtm);
      }
    }

    // tDist rule
    GroundLiteral tDistHead = createRegLiteral("totNear");
    ArrayList<FaspFuzzyExpression> tDistBody = new ArrayList<FaspFuzzyExpression>();
    for (FaspConstant a : atm) {
      for (FaspConstant t : town) {
        tDistBody.add(createRegLiteral("atmNear", a, t));
      }
View Full Code Here

//      }
//    }
//    GroundRule tDistRule = new GroundRegularRule(tDistHead, tDistBody, new TM());
//    rules.add(tDistRule);

    GroundLiteral aHead = createRegLiteral("a");
    ArrayList<FaspFuzzyExpression> aBody = new ArrayList<FaspFuzzyExpression>();
    aBody.add(createNafLiteral("b",new NM()));
    GroundRule aRule = new GroundRegularRule(aHead,aBody,new TW());

    GroundLiteral bHead = createRegLiteral("b");
    ArrayList<FaspFuzzyExpression> bBody = new ArrayList<FaspFuzzyExpression>();
    bBody.add(createNafLiteral("a",new NM()));
    GroundRule bRule = new GroundRegularRule(bHead,bBody,new TW());

    ArrayList<GroundRule> rules = new ArrayList<GroundRule>();
    rules.add(aRule);
    rules.add(bRule);
    GroundProgram prog = new GroundProgram(rules);

    int defaultBound = 10;
    int k = 1;

    Map<String, Double> solution = null;
    FaspInterpretation i = null;
    List<FuzzyClause> clauses = prog.createCompletion2();

    for (FuzzyClause c : clauses) {
      System.out.println(c);
    }


    FuzzyToIntegerConvertor ficonv =
        new FuzzyToIntegerConvertor(defaultBound, k);

//    DoubleNegationEliminator dnegElim = new DoubleNegationEliminator();
//    ArrayList<FuzzyClause> newClauses = new ArrayList<FuzzyClause>();
//    for (FuzzyClause c : clauses) {
//      ArrayList<Literal> newLiterals = new ArrayList<Literal>();
//      for (Literal l : c.getDisjuncts()) {
//        FuzzyLiteral flit = (FuzzyLiteral) l;
//        FuzzyExpression newExp = flit.getExpression().accept(dnegElim);
//        newLiterals.add(new FuzzyLiteral(flit.getLowerBound(),
//            flit.getUpperBound(), newExp));
//      }
//      newClauses.add(new FuzzyClause(newLiterals));
//    }

    // overwrite the old clauses with the simplified ones ...
//    clauses = newClauses;

    HashMap trivialAssignments = new HashMap();
//    if (FiniteReductionConfig.optimizeClauses) {
//      boolean changed = true;
//      while (changed) {
//        DomainFinder.simplify(clauses);
//        changed = DomainFinder.eliminateTriviallySatisfiableClauses(clauses, trivialAssignments);
//      }
//    }

    for (FuzzyClause c : clauses) {
      ficonv.addFuzzyClause(c);
    }

    TailorSolver solv = new TailorSolver("/home/jeroen/programming/tailorV0.3.2/tailor.jar",
        "/home/jeroen/programming/minion-0.10/bin/minion");
    solv.read(ficonv.convertToCSPProblem());

    System.out.println("Ok, read file. Now solving ...");
    CSPSolution cspSolution = solv.solve();
    solution = ficonv.convertCSPSolutionToFuzzyModel(cspSolution);
    System.out.println("Solving ended!");

    if (solution != null) {
      solution.putAll(trivialAssignments);
      checkModel(clauses, solution);
      printSolution(solution);
      Map<GroundLiteral, Double> interp = new HashMap<GroundLiteral, Double>();
      for (String s : solution.keySet()) {
        GroundLiteral lit = parseLiteral(s);
        interp.put(lit, solution.get(s));
      }
      i = new FaspInterpretation(interp);
      if (prog.isAnswerSet(i)) {
        System.out.println("is answer set!");
View Full Code Here

    ArrayList<FaspConstant> pargs = new ArrayList<FaspConstant>();
    for (FaspConstant c : args) {
      pargs.add(c);
    }
    GroundPredicate p = new GroundPredicate(name, pargs);
    return new GroundLiteral(p, false, naf, nafOp);
  }
View Full Code Here

        System.out.println("Main resource = " + ff.getMain());
        String[] resources = ff.getResourceIds().toArray(new String[0]);
        for(int i=0; i<resources.length; i++){
            ArrayList<FaspFuzzyExpression> listii = new ArrayList<FaspFuzzyExpression>();
            listii.add(new LattVal(1.0));
            rules.add(new GroundRegularRule(new GroundLiteral(new GroundPredicate(
                    "SIMR("+resources[i]+","+resources[i]+")"),false, false,null),listii,new ID()));
            for(int j=i+1; j<resources.length; j++){
                //JACCARD RULES
                double sim_tag = ff.getJaccard(resources[i], resources[j], Item.RESOURCE, Item.TAG);
                double sim_user = ff.getJaccard(resources[i], resources[j], Item.RESOURCE, Item.USER);

                ArrayList<FaspFuzzyExpression> list = new ArrayList<FaspFuzzyExpression>(1);
                ArrayList<FaspFuzzyExpression> list_reverse = new ArrayList<FaspFuzzyExpression>(1);
                list.add(new LattVal((((double)1/2)*sim_tag)*(((double)1/2)*sim_user)));

                GroundLiteral SIMR_litt =
                new GroundLiteral(new GroundPredicate("SIMR("+resources[i]+","+resources[j]+")"),false, false,null);

                GroundRegularRule rule = new GroundRegularRule(SIMR_litt, list, new ID());

                list_reverse.add(SIMR_litt);

                GroundRegularRule rule_reverse = new GroundRegularRule(
                        new GroundLiteral(new GroundPredicate("SIMR("+resources[j]+","+resources[i]+")"),
                        false, false,null), list_reverse, new ID());

                rules.add(rule);
                rules.add(rule_reverse);

                //Recursieve regels onderdeel T              
                ArrayList<FaspFuzzyExpression> list_op1_T1 = new ArrayList<FaspFuzzyExpression>();
                ArrayList<FaspFuzzyExpression> list_op1_T2 = new ArrayList<FaspFuzzyExpression>();
                //MAX van T1 met alle tags van T2
                for(String tag_i : ff.getResource(resources[i]).getItemList(Item.TAG)){
                    ArrayList<FaspFuzzyExpression> list_max_T1 = new ArrayList<FaspFuzzyExpression>();
                    for(String tag_j : ff.getResource(resources[j]).getItemList(Item.TAG)){
                        list_max_T1.add(new GroundLiteral(new GroundPredicate("SIMT("+tag_i+","+tag_j+")"),false, false,null));
                    }
                    GroundLiteral litt_max_T1 = new GroundLiteral(new GroundPredicate(
                            "MAXR_"+resources[i]+"_"+resources[j]+"_T1_"+tag_i),false, false,null);
                    GroundRegularRule rule_max_T1 = new GroundRegularRule(litt_max_T1, list_max_T1, new MULTIMAX());
                    rules.add(rule_max_T1);
                    list_op1_T1.add(litt_max_T1);
                }
                //MAX van T2 met alle tags van T1
                for(String tag_j : ff.getResource(resources[j]).getItemList(Item.TAG)){
                    ArrayList<FaspFuzzyExpression> list_max_T2 = new ArrayList<FaspFuzzyExpression>();
                    for(String tag_i : ff.getResource(resources[i]).getItemList(Item.TAG)){
                        list_max_T2.add(new GroundLiteral(new GroundPredicate("SIMT("+tag_j+","+tag_i+")"),false, false,null));
                    }
                    GroundLiteral litt_max_T2 = new GroundLiteral(new GroundPredicate(
                            "MAXR_"+resources[j]+"_"+resources[i]+"_T2_"+tag_j),false, false,null);
                    GroundRegularRule rule_max_T2 = new GroundRegularRule(litt_max_T2, list_max_T2, new MULTIMAX());
                    rules.add(rule_max_T2);
                    list_op1_T2.add(litt_max_T2);
                }
                //op1 van maxT1 en maxT2
                GroundLiteral litt_op1_T1 = new GroundLiteral(new GroundPredicate(
                        "OP1R_"+resources[i]+"_"+resources[j]+"_T1"),false,false,null);
                GroundLiteral litt_op1_T2 = new GroundLiteral(new GroundPredicate(
                        "OP1R_"+resources[i]+"_"+resources[j]+"_T2"),false,false,null);
                rules.add(new GroundRegularRule(litt_op1_T1,list_op1_T1, op1));
                rules.add(new GroundRegularRule(litt_op1_T2,list_op1_T2, op1));
                //op2 van op1T1 en op1T2
                ArrayList<FaspFuzzyExpression> list_op2_T = new ArrayList<FaspFuzzyExpression>();
                list_op2_T.add(litt_op1_T1);
                list_op2_T.add(litt_op1_T2);
                GroundLiteral litt_op2_T = new GroundLiteral(new GroundPredicate(
                        "OP2R_"+resources[i]+"_"+resources[j]+"_T"),false,false,null);
                rules.add(new GroundRegularRule(litt_op2_T, list_op2_T, op2));

                //Recursieve regels onderdeel U
                ArrayList<FaspFuzzyExpression> list_op1_U1 = new ArrayList<FaspFuzzyExpression>();
                ArrayList<FaspFuzzyExpression> list_op1_U2 = new ArrayList<FaspFuzzyExpression>();
                //MAX van U1 met alle tags van U2
                for(String user_i : ff.getResource(resources[i]).getItemList(Item.USER)){
                    ArrayList<FaspFuzzyExpression> list_max_U1 = new ArrayList<FaspFuzzyExpression>();
                    for(String user_j : ff.getResource(resources[j]).getItemList(Item.USER)){
                        list_max_U1.add(new GroundLiteral(new GroundPredicate("SIMU("+user_i+","+user_j+")"),false, false,null));
                    }
                    GroundLiteral litt_max_U1 = new GroundLiteral(new GroundPredicate(
                            "MAXR_"+resources[i]+"_"+resources[j]+"_U1_"+user_i),false, false,null);
                    GroundRegularRule rule_max_U1 = new GroundRegularRule(litt_max_U1, list_max_U1, new MULTIMAX());
                    rules.add(rule_max_U1);
                    list_op1_U1.add(litt_max_U1);
                }
                //MAX van U2 met alle tags van U1
                for(String user_j : ff.getResource(resources[j]).getItemList(Item.USER)){
                    ArrayList<FaspFuzzyExpression> list_max_U2 = new ArrayList<FaspFuzzyExpression>();
                    for(String user_i : ff.getResource(resources[i]).getItemList(Item.USER)){
                        list_max_U2.add(new GroundLiteral(new GroundPredicate("SIMU("+user_j+","+user_i+")"),false, false,null));
                    }
                    GroundLiteral litt_max_U2 = new GroundLiteral(new GroundPredicate(
                            "MAXR_"+resources[j]+"_"+resources[i]+"_U2_"+user_j),false, false,null);
                    GroundRegularRule rule_max_U2 = new GroundRegularRule(litt_max_U2, list_max_U2, new MULTIMAX());
                    rules.add(rule_max_U2);
                    list_op1_U2.add(litt_max_U2);
                }
                //op1 van maxU1 en maxU2
                GroundLiteral litt_op1_U1 = new GroundLiteral(new GroundPredicate(
                        "OP1R_"+resources[i]+"_"+resources[j]+"_U1"),false,false,null);
                GroundLiteral litt_op1_U2 = new GroundLiteral(new GroundPredicate(
                        "OP1R_"+resources[i]+"_"+resources[j]+"_U2"),false,false,null);
                rules.add(new GroundRegularRule(litt_op1_U1, list_op1_U1, op1));
                rules.add(new GroundRegularRule(litt_op1_U2, list_op1_U2, op1));
                //op2 van op1U1 en op1U2
                ArrayList<FaspFuzzyExpression> list_op2_U = new ArrayList<FaspFuzzyExpression>();
                list_op2_U.add(litt_op1_U1);
                list_op2_U.add(litt_op1_U2);
                GroundLiteral litt_op2_U = new GroundLiteral(new GroundPredicate(
                        "OP2R_"+resources[i]+"_"+resources[j]+"_U"),false,false,null);
                rules.add(new GroundRegularRule(litt_op2_U, list_op2_U, op2));

                //op3 van op2T en op2U
                ArrayList<FaspFuzzyExpression> list_op3 = new ArrayList<FaspFuzzyExpression>();
                list_op3.add(litt_op2_U);
                list_op3.add(litt_op2_T);
                rules.add(new GroundRegularRule(SIMR_litt,list_op3, op3));
            }
        }

        //RULES USERS
        String[] users = ff.getUserIds().toArray(new String[0]);
        for(int i=0; i<users.length; i++){
            ArrayList<FaspFuzzyExpression> listii = new ArrayList<FaspFuzzyExpression>();
            listii.add(new LattVal(1.0));
            rules.add(new GroundRegularRule(new GroundLiteral(new GroundPredicate(
                    "SIMU("+users[i]+","+users[i]+")"),false, false,null),listii,new ID()));
            for(int j=i+1; j<users.length; j++){
                //JACCARD RULES
                double sim_tag = ff.getJaccard(users[i], users[j], Item.USER, Item.TAG);
                double sim_res = ff.getJaccard(users[i], users[j], Item.USER, Item.RESOURCE);

                ArrayList<FaspFuzzyExpression> list = new ArrayList<FaspFuzzyExpression>(1);
                ArrayList<FaspFuzzyExpression> list_reverse = new ArrayList<FaspFuzzyExpression>(1);
                list.add(new LattVal((((double)1/2)*sim_tag)*(((double)1/2)*sim_res)));

                GroundLiteral SIMU_litt =
                new GroundLiteral(new GroundPredicate("SIMU("+users[i]+","+users[j]+")"),false, false,null);

                GroundRegularRule rule = new GroundRegularRule(SIMU_litt, list, new ID());

                list_reverse.add(SIMU_litt);

                GroundRegularRule rule_reverse = new GroundRegularRule(
                        new GroundLiteral(new GroundPredicate("SIMU("+users[j]+","+users[i]+")"),
                        false, false,null), list_reverse, new ID());

                rules.add(rule);
                rules.add(rule_reverse);

                //Recursieve regels onderdeel T
                ArrayList<FaspFuzzyExpression> list_op1_T1 = new ArrayList<FaspFuzzyExpression>();
                ArrayList<FaspFuzzyExpression> list_op1_T2 = new ArrayList<FaspFuzzyExpression>();
                //MAX van T1 met alle tags van T2
                for(String tag_i : ff.getUser(users[i]).getItemList(Item.TAG)){
                    ArrayList<FaspFuzzyExpression> list_max_T1 = new ArrayList<FaspFuzzyExpression>();
                    for(String tag_j : ff.getUser(users[j]).getItemList(Item.TAG)){
                        list_max_T1.add(new GroundLiteral(new GroundPredicate("SIMT("+tag_i+","+tag_j+")"),false, false,null));
                    }
                    GroundLiteral litt_max_T1 = new GroundLiteral(new GroundPredicate(
                            "MAXU_"+users[i]+"_"+users[j]+"_T1_"+tag_i),false, false,null);
                    GroundRegularRule rule_max_T1 = new GroundRegularRule(litt_max_T1, list_max_T1, new MULTIMAX());
                    rules.add(rule_max_T1);
                    list_op1_T1.add(litt_max_T1);
                }
                //MAX van T2 met alle tags van T1
                for(String tag_j : ff.getUser(users[j]).getItemList(Item.TAG)){
                    ArrayList<FaspFuzzyExpression> list_max_T2 = new ArrayList<FaspFuzzyExpression>();
                    for(String tag_i : ff.getUser(users[i]).getItemList(Item.TAG)){
                        list_max_T2.add(new GroundLiteral(new GroundPredicate("SIMT("+tag_j+","+tag_i+")"),false, false,null));
                    }
                    GroundLiteral litt_max_T2 = new GroundLiteral(new GroundPredicate(
                            "MAXU_"+users[j]+"_"+users[i]+"_T2_"+tag_j),false, false,null);
                    GroundRegularRule rule_max_T2 = new GroundRegularRule(litt_max_T2, list_max_T2, new MULTIMAX());
                    rules.add(rule_max_T2);
                    list_op1_T2.add(litt_max_T2);
                }
                //op1 van maxT1 en maxT2
                GroundLiteral litt_op1_T1 = new GroundLiteral(new GroundPredicate(
                        "OP1U_"+users[i]+"_"+users[j]+"_T1"),false,false,null);
                GroundLiteral litt_op1_T2 = new GroundLiteral(new GroundPredicate(
                        "OP1U_"+users[i]+"_"+users[j]+"_T2"),false,false,null);
                rules.add(new GroundRegularRule(litt_op1_T1,list_op1_T1, op1));
                rules.add(new GroundRegularRule(litt_op1_T2,list_op1_T2, op1));
                //op2 van op1T1 en op1T2
                ArrayList<FaspFuzzyExpression> list_op2_T = new ArrayList<FaspFuzzyExpression>();
                list_op2_T.add(litt_op1_T1);
                list_op2_T.add(litt_op1_T2);
                GroundLiteral litt_op2_T = new GroundLiteral(new GroundPredicate(
                        "OP2U_"+users[i]+"_"+users[j]+"_T"),false,false,null);
                rules.add(new GroundRegularRule(litt_op2_T, list_op2_T, op2));

                //Recursieve regels onderdeel R
                ArrayList<FaspFuzzyExpression> list_op1_R1 = new ArrayList<FaspFuzzyExpression>();
                ArrayList<FaspFuzzyExpression> list_op1_R2 = new ArrayList<FaspFuzzyExpression>();
                //MAX van R1 met alle tags van R2
                for(String res_i : ff.getUser(users[i]).getItemList(Item.RESOURCE)){
                    ArrayList<FaspFuzzyExpression> list_max_R1 = new ArrayList<FaspFuzzyExpression>();
                    for(String res_j : ff.getUser(users[j]).getItemList(Item.RESOURCE)){
                        list_max_R1.add(new GroundLiteral(new GroundPredicate("SIMR("+res_i+","+res_j+")"),false, false,null));
                    }
                    GroundLiteral litt_max_R1 = new GroundLiteral(new GroundPredicate(
                            "MAXU_"+users[i]+"_"+users[j]+"_R1_"+res_i),false, false,null);
                    GroundRegularRule rule_max_R1 = new GroundRegularRule(litt_max_R1, list_max_R1, new MULTIMAX());
                    rules.add(rule_max_R1);
                    list_op1_R1.add(litt_max_R1);
                }
                //MAX van R2 met alle tags van R1
                for(String res_j : ff.getUser(users[j]).getItemList(Item.RESOURCE)){
                    ArrayList<FaspFuzzyExpression> list_max_R2 = new ArrayList<FaspFuzzyExpression>();
                    for(String res_i : ff.getUser(users[i]).getItemList(Item.RESOURCE)){
                        list_max_R2.add(new GroundLiteral(new GroundPredicate("SIMR("+res_j+","+res_i+")"),false, false,null));
                    }
                    GroundLiteral litt_max_R2 = new GroundLiteral(new GroundPredicate(
                            "MAXU_"+users[j]+"_"+users[i]+"_R2_"+res_j),false, false,null);
                    GroundRegularRule rule_max_R2 = new GroundRegularRule(litt_max_R2, list_max_R2, new MULTIMAX());
                    rules.add(rule_max_R2);
                    list_op1_R2.add(litt_max_R2);
                }
                //op1 van maxR1 en maxR2
                GroundLiteral litt_op1_R1 = new GroundLiteral(new GroundPredicate(
                        "OP1U_"+users[i]+"_"+users[j]+"_R1"),false,false,null);
                GroundLiteral litt_op1_R2 = new GroundLiteral(new GroundPredicate(
                        "OP1U_"+users[i]+"_"+users[j]+"_R2"),false,false,null);
                rules.add(new GroundRegularRule(litt_op1_R1, list_op1_R1, op1));
                rules.add(new GroundRegularRule(litt_op1_R2, list_op1_R2, op1));
                //op2 van op1R1 en op1R2
                ArrayList<FaspFuzzyExpression> list_op2_R = new ArrayList<FaspFuzzyExpression>();
                list_op2_R.add(litt_op1_R1);
                list_op2_R.add(litt_op1_R2);
                GroundLiteral litt_op2_R = new GroundLiteral(new GroundPredicate(
                        "OP2U_"+users[i]+"_"+users[j]+"_R"),false,false,null);
                rules.add(new GroundRegularRule(litt_op2_R, list_op2_R, op2));

                //op3 van op2R en op2R
                ArrayList<FaspFuzzyExpression> list_op3 = new ArrayList<FaspFuzzyExpression>();
                list_op3.add(litt_op2_T);
                list_op3.add(litt_op2_R);
                rules.add(new GroundRegularRule(SIMU_litt,list_op3, op3));
            }
        }

        //RULES TAGS
        String[] tags = ff.getTagIds().toArray(new String[0]);
        for(int i=0; i<tags.length; i++){
            ArrayList<FaspFuzzyExpression> listii = new ArrayList<FaspFuzzyExpression>();
            listii.add(new LattVal(1.0));
            rules.add(new GroundRegularRule(new GroundLiteral(new GroundPredicate(
                    "SIMT("+tags[i]+","+tags[i]+")"),false, false,null),listii,new ID()));
            for(int j=i+1; j<tags.length; j++){
                //JACCARD RULES
                double sim_user = ff.getJaccard(tags[i], tags[j], Item.TAG, Item.USER);
                double sim_res = ff.getJaccard(tags[i], tags[j], Item.TAG, Item.RESOURCE);

                ArrayList<FaspFuzzyExpression> list = new ArrayList<FaspFuzzyExpression>(1);
                ArrayList<FaspFuzzyExpression> list_reverse = new ArrayList<FaspFuzzyExpression>(1);
                list.add(new LattVal((((double)1/2)*sim_user)*(((double)1/2)*sim_res)));

                GroundLiteral SIMT_litt =
                new GroundLiteral(new GroundPredicate("SIMT("+tags[i]+","+tags[j]+")"),false, false,null);

                GroundRegularRule rule = new GroundRegularRule(SIMT_litt, list, new ID());

                list_reverse.add(SIMT_litt);

                GroundRegularRule rule_reverse = new GroundRegularRule(
                        new GroundLiteral(new GroundPredicate("SIMT("+tags[j]+","+tags[i]+")"),
                        false, false,null), list_reverse, new ID());

                rules.add(rule);
                rules.add(rule_reverse);

                //Recursieve regels onderdeel U  
                ArrayList<FaspFuzzyExpression> list_op1_U1 = new ArrayList<FaspFuzzyExpression>();
                ArrayList<FaspFuzzyExpression> list_op1_U2 = new ArrayList<FaspFuzzyExpression>();
                //MAX van U1 met alle tags van U2
                for(String user_i : ff.getTag(tags[i]).getItemList(Item.USER)){
                    ArrayList<FaspFuzzyExpression> list_max_U1 = new ArrayList<FaspFuzzyExpression>();
                    for(String user_j : ff.getTag(tags[j]).getItemList(Item.USER)){
                        list_max_U1.add(new GroundLiteral(new GroundPredicate("SIMU("+user_i+","+user_j+")"),false, false,null));
                    }
                    GroundLiteral litt_max_U1 = new GroundLiteral(new GroundPredicate(
                            "MAXT_"+tags[i]+"_"+tags[j]+"_U1_"+user_i),false, false,null);
                    GroundRegularRule rule_max_U1 = new GroundRegularRule(litt_max_U1, list_max_U1, new MULTIMAX());
                    rules.add(rule_max_U1);
                    list_op1_U1.add(litt_max_U1);
                }
                //MAX van U2 met alle tags van U1
                for(String user_j : ff.getTag(tags[j]).getItemList(Item.USER)){
                    ArrayList<FaspFuzzyExpression> list_max_U2 = new ArrayList<FaspFuzzyExpression>();
                    for(String user_i : ff.getTag(tags[i]).getItemList(Item.USER)){
                        list_max_U2.add(new GroundLiteral(new GroundPredicate("SIMU("+user_j+","+user_i+")"),false, false,null));
                    }
                    GroundLiteral litt_max_U2 = new GroundLiteral(new GroundPredicate(
                            "MAXT_"+tags[j]+"_"+tags[i]+"_U2_"+user_j),false, false,null);
                    GroundRegularRule rule_max_U2 = new GroundRegularRule(litt_max_U2, list_max_U2, new MULTIMAX());
                    rules.add(rule_max_U2);
                    list_op1_U2.add(litt_max_U2);
                }
                //op1 van maxU1 en maxU2
                GroundLiteral litt_op1_U1 = new GroundLiteral(new GroundPredicate(
                        "OP1T_"+tags[i]+"_"+tags[j]+"_U1"),false,false,null);
                GroundLiteral litt_op1_U2 = new GroundLiteral(new GroundPredicate(
                        "OP1T_"+tags[i]+"_"+tags[j]+"_U2"),false,false,null);
                rules.add(new GroundRegularRule(litt_op1_U1,list_op1_U1, op1));
                rules.add(new GroundRegularRule(litt_op1_U2,list_op1_U2, op1));
                //op2 van op1T1 en op1T2
                ArrayList<FaspFuzzyExpression> list_op2_U = new ArrayList<FaspFuzzyExpression>();
                list_op2_U.add(litt_op1_U1);
                list_op2_U.add(litt_op1_U2);
                GroundLiteral litt_op2_U = new GroundLiteral(new GroundPredicate(
                        "OP2T_"+tags[i]+"_"+tags[j]+"_U"),false,false,null);
                rules.add(new GroundRegularRule(litt_op2_U, list_op2_U, op2));

                //Recursieve regels onderdeel R
                ArrayList<FaspFuzzyExpression> list_op1_R1 = new ArrayList<FaspFuzzyExpression>();
                ArrayList<FaspFuzzyExpression> list_op1_R2 = new ArrayList<FaspFuzzyExpression>();
                //MAX van R1 met alle tags van R2
                for(String res_i : ff.getTag(tags[i]).getItemList(Item.RESOURCE)){
                    ArrayList<FaspFuzzyExpression> list_max_R1 = new ArrayList<FaspFuzzyExpression>();
                    for(String res_j : ff.getTag(tags[j]).getItemList(Item.RESOURCE)){
                        list_max_R1.add(new GroundLiteral(new GroundPredicate("SIMR("+res_i+","+res_j+")"),false, false,null));
                    }
                    GroundLiteral litt_max_R1 = new GroundLiteral(new GroundPredicate(
                            "MAXT_"+tags[i]+"_"+tags[j]+"_R1_"+res_i),false, false,null);
                    GroundRegularRule rule_max_R1 = new GroundRegularRule(litt_max_R1, list_max_R1, new MULTIMAX());
                    rules.add(rule_max_R1);
                    list_op1_R1.add(litt_max_R1);
                }
                //MAX van R2 met alle tags van R1
                for(String res_j : ff.getTag(tags[j]).getItemList(Item.RESOURCE)){
                    ArrayList<FaspFuzzyExpression> list_max_R2 = new ArrayList<FaspFuzzyExpression>();
                    for(String res_i : ff.getTag(tags[i]).getItemList(Item.RESOURCE)){
                        list_max_R2.add(new GroundLiteral(new GroundPredicate("SIMR("+res_j+","+res_i+")"),false, false,null));
                    }
                    GroundLiteral litt_max_R2 = new GroundLiteral(new GroundPredicate(
                            "MAXT_"+tags[j]+"_"+tags[i]+"_R2_"+res_j),false, false,null);
                    GroundRegularRule rule_max_R2 = new GroundRegularRule(litt_max_R2, list_max_R2, new MULTIMAX());
                    rules.add(rule_max_R2);
                    list_op1_R2.add(litt_max_R2);
                }
                //op1 van maxR1 en maxR2
                GroundLiteral litt_op1_R1 = new GroundLiteral(new GroundPredicate(
                        "OP1T_"+tags[i]+"_"+tags[j]+"_R1"),false,false,null);
                GroundLiteral litt_op1_R2 = new GroundLiteral(new GroundPredicate(
                        "OP1T_"+tags[i]+"_"+tags[j]+"_R2"),false,false,null);
                rules.add(new GroundRegularRule(litt_op1_R1, list_op1_R1, op1));
                rules.add(new GroundRegularRule(litt_op1_R2, list_op1_R2, op1));
                //op2 van op1R1 en op1R2
                ArrayList<FaspFuzzyExpression> list_op2_R = new ArrayList<FaspFuzzyExpression>();
                list_op2_R.add(litt_op1_R1);
                list_op2_R.add(litt_op1_R2);
                GroundLiteral litt_op2_R = new GroundLiteral(new GroundPredicate(
                        "OP2T_"+tags[i]+"_"+tags[j]+"_R"),false,false,null);
                rules.add(new GroundRegularRule(litt_op2_R, list_op2_R, op2));

                //op3 van op2T en op2U
                ArrayList<FaspFuzzyExpression> list_op3 = new ArrayList<FaspFuzzyExpression>();
View Full Code Here

        //All groundLiterals

            /*r*/

        GroundLiteral r1r1 = new GroundLiteral(new GroundPredicate("SIMR("+r1+","+r1+")"),false, false,null);
        GroundLiteral r2r2 = new GroundLiteral(new GroundPredicate("SIMR("+r2+","+r2+")"),false, false,null);
        GroundLiteral r1r2 = new GroundLiteral(new GroundPredicate("SIMR("+r1+","+r2+")"),false, false,null);
        GroundLiteral r2r1 = new GroundLiteral(new GroundPredicate("SIMR("+r2+","+r1+")"),false, false,null);

        GroundLiteral op2_r1r2t = new GroundLiteral(new GroundPredicate("OP2R_tag("+r1+","+r2+")"),false, false,null);
        GroundLiteral op2_r1r2u = new GroundLiteral(new GroundPredicate("OP2R_res("+r1+","+r2+")"),false, false,null);
        GroundLiteral op1_r1r2t1 = new GroundLiteral(new GroundPredicate("OP1R_tag1("+r1+","+r2+")"),false, false,null);
        GroundLiteral op1_r1r2u1 = new GroundLiteral(new GroundPredicate("OP1R_res1("+r1+","+r2+")"),false, false,null);
        GroundLiteral op1_r1r2t2 = new GroundLiteral(new GroundPredicate("OP1R_tag2("+r1+","+r2+")"),false, false,null);
        GroundLiteral op1_r1r2u2 = new GroundLiteral(new GroundPredicate("OP1R_res2("+r1+","+r2+")"),false, false,null);

            /*u*/

        GroundLiteral uIuI = new GroundLiteral(new GroundPredicate("SIMU("+uI+","+uI+")"),false, false,null);
        GroundLiteral uIIuII = new GroundLiteral(new GroundPredicate("SIMU("+uII+","+uII+")"),false, false,null);
        GroundLiteral uIIIuIII = new GroundLiteral(new GroundPredicate("SIMU("+uIII+","+uIII+")"),false, false,null);
        GroundLiteral uIuII = new GroundLiteral(new GroundPredicate("SIMU("+uI+","+uII+")"),false, false,null);
        GroundLiteral uIIuI = new GroundLiteral(new GroundPredicate("SIMU("+uII+","+uI+")"),false, false,null);
        GroundLiteral uIuIII = new GroundLiteral(new GroundPredicate("SIMU("+uI+","+uIII+")"),false, false,null);
        GroundLiteral uIIIuI = new GroundLiteral(new GroundPredicate("SIMU("+uIII+","+uI+")"),false, false,null);
        GroundLiteral uIIuIII = new GroundLiteral(new GroundPredicate("SIMU("+uII+","+uIII+")"),false, false,null);
        GroundLiteral uIIIuII = new GroundLiteral(new GroundPredicate("SIMU("+uIII+","+uII+")"),false, false,null);
       
            /*t*/

        GroundLiteral tAtA = new GroundLiteral(new GroundPredicate("SIMT("+tA+","+tA+")"),false, false,null);
        GroundLiteral tBtB = new GroundLiteral(new GroundPredicate("SIMT("+tB+","+tB+")"),false, false,null);
        GroundLiteral tCtC = new GroundLiteral(new GroundPredicate("SIMT("+tC+","+tC+")"),false, false,null);
        GroundLiteral tDtD = new GroundLiteral(new GroundPredicate("SIMT("+tD+","+tD+")"),false, false,null);
        GroundLiteral tAtB = new GroundLiteral(new GroundPredicate("SIMT("+tA+","+tB+")"),false, false,null);
        GroundLiteral tBtA = new GroundLiteral(new GroundPredicate("SIMT("+tB+","+tA+")"),false, false,null);
        GroundLiteral tAtC = new GroundLiteral(new GroundPredicate("SIMT("+tA+","+tC+")"),false, false,null);
        GroundLiteral tCtA = new GroundLiteral(new GroundPredicate("SIMT("+tC+","+tA+")"),false, false,null);
        GroundLiteral tAtD = new GroundLiteral(new GroundPredicate("SIMT("+tA+","+tD+")"),false, false,null);
        GroundLiteral tDtA = new GroundLiteral(new GroundPredicate("SIMT("+tD+","+tA+")"),false, false,null);
        GroundLiteral tBtC = new GroundLiteral(new GroundPredicate("SIMT("+tB+","+tC+")"),false, false,null);
        GroundLiteral tCtB = new GroundLiteral(new GroundPredicate("SIMT("+tC+","+tB+")"),false, false,null);
        GroundLiteral tBtD = new GroundLiteral(new GroundPredicate("SIMT("+tB+","+tD+")"),false, false,null);
        GroundLiteral tDtB = new GroundLiteral(new GroundPredicate("SIMT("+tD+","+tB+")"),false, false,null);
        GroundLiteral tCtD = new GroundLiteral(new GroundPredicate("SIMT("+tC+","+tD+")"),false, false,null);
        GroundLiteral tDtC = new GroundLiteral(new GroundPredicate("SIMT("+tD+","+tC+")"),false, false,null);


        ArrayList<GroundRule> rules = new ArrayList<GroundRule>();

        //JACCARD GEMIDDELD

        ArrayList<FaspFuzzyExpression> l1 = new ArrayList<FaspFuzzyExpression>(); l1.add(new LattVal(1.0));
        ArrayList<FaspFuzzyExpression> l0 = new ArrayList<FaspFuzzyExpression>(); l0.add(new LattVal(0.0));
        ArrayList<FaspFuzzyExpression> lr1r2 = new ArrayList<FaspFuzzyExpression>(); lr1r2.add(new LattVal(0.41667));
        ArrayList<FaspFuzzyExpression> luIuII = new ArrayList<FaspFuzzyExpression>(); luIuII.add(new LattVal(0.625));
        ArrayList<FaspFuzzyExpression> luIuIII = new ArrayList<FaspFuzzyExpression>(); luIuIII.add(new LattVal(0.66667));
        ArrayList<FaspFuzzyExpression> luIIuIII = new ArrayList<FaspFuzzyExpression>(); luIIuIII.add(new LattVal(0.325));
        ArrayList<FaspFuzzyExpression> ltAtB = new ArrayList<FaspFuzzyExpression>(); ltAtB.add(new LattVal(0.25));
        ArrayList<FaspFuzzyExpression> ltAtC = new ArrayList<FaspFuzzyExpression>(); ltAtC.add(new LattVal(0.41667));
        ArrayList<FaspFuzzyExpression> ltAtD = new ArrayList<FaspFuzzyExpression>(); ltAtD.add(new LattVal(0.5));
        ArrayList<FaspFuzzyExpression> ltBtC = new ArrayList<FaspFuzzyExpression>(); ltBtC.add(new LattVal(0.58333));
        ArrayList<FaspFuzzyExpression> ltBtD = new ArrayList<FaspFuzzyExpression>(); ltBtD.add(new LattVal(0.75));
        ArrayList<FaspFuzzyExpression> ltCtD = new ArrayList<FaspFuzzyExpression>(); ltCtD.add(new LattVal(0.83333));

            /*r*/
        rules.add(new GroundRegularRule(r1r1,l1,new ID()));
        rules.add(new GroundRegularRule(r2r2,l1,new ID()));
        rules.add(new GroundRegularRule(r1r2,lr1r2,new ID()));
        rules.add(new GroundRegularRule(r2r1,lr1r2,new ID()));
            /*u*/
        rules.add(new GroundRegularRule(uIuI,l1,new ID()));
        rules.add(new GroundRegularRule(uIIuII,l1,new ID()));
        rules.add(new GroundRegularRule(uIIIuIII,l1,new ID()));
        rules.add(new GroundRegularRule(uIuII,luIuII,new ID()));
        rules.add(new GroundRegularRule(uIIuI,luIuII,new ID()));
        rules.add(new GroundRegularRule(uIuIII,luIuIII,new ID()));
        rules.add(new GroundRegularRule(uIIIuI,luIuIII,new ID()));
        rules.add(new GroundRegularRule(uIIuIII,luIIuIII,new ID()));
        rules.add(new GroundRegularRule(uIIIuII,luIIuIII,new ID()));
            /*t*/
        rules.add(new GroundRegularRule(tAtA,l1,new ID()));
        rules.add(new GroundRegularRule(tBtB,l1,new ID()));
        rules.add(new GroundRegularRule(tCtC,l1,new ID()));
        rules.add(new GroundRegularRule(tDtD,l1,new ID()));
        rules.add(new GroundRegularRule(tAtB,ltAtB,new ID()));
        rules.add(new GroundRegularRule(tBtA,ltAtB,new ID()));
        rules.add(new GroundRegularRule(tAtC,ltAtC,new ID()));
        rules.add(new GroundRegularRule(tCtA,ltAtC,new ID()));
        rules.add(new GroundRegularRule(tAtD,ltAtD,new ID()));
        rules.add(new GroundRegularRule(tDtA,ltAtD,new ID()));
        rules.add(new GroundRegularRule(tBtC,ltBtC,new ID()));
        rules.add(new GroundRegularRule(tCtB,ltBtC,new ID()));
        rules.add(new GroundRegularRule(tBtD,ltBtD,new ID()));
        rules.add(new GroundRegularRule(tDtB,ltBtD,new ID()));
        rules.add(new GroundRegularRule(tCtD,ltCtD,new ID()));
        rules.add(new GroundRegularRule(tDtC,ltCtD,new ID()));


        //RECURSIEVE REGELS

        /*R*/
        /**RT**/
        ArrayList<FaspFuzzyExpression> op1_r1r2t1_list = new ArrayList<FaspFuzzyExpression>();
        for(String tag1 : map_res_on_tag.get(r1)){
            ArrayList<FaspFuzzyExpression> max_r1r2t1_list = new ArrayList<FaspFuzzyExpression>();
            for(String tag2 : map_res_on_tag.get(r2)){
                max_r1r2t1_list.add(new GroundLiteral(new GroundPredicate("SIMT("+tag1+","+tag2+")"),false, false,null));
            }
            GroundLiteral maxTR = new GroundLiteral(new GroundPredicate("MAXTR(tag2|"+tag1+")"),false, false,null);
            rules.add(new GroundRegularRule(maxTR, max_r1r2t1_list,new MULTIMAX()));
            op1_r1r2t1_list.add(maxTR);
        }
        rules.add(new GroundRegularRule(op1_r1r2t1, op1_r1r2t1_list, op1));
        ArrayList<FaspFuzzyExpression> op1_r1r2t2_list = new ArrayList<FaspFuzzyExpression>();
        for(String tag2 : map_res_on_tag.get(r2)){
            ArrayList<FaspFuzzyExpression> max_r1r2t2_list = new ArrayList<FaspFuzzyExpression>();
            for(String tag1 : map_res_on_tag.get(r1)){
                max_r1r2t2_list.add(new GroundLiteral(new GroundPredicate("SIMT("+tag2+","+tag1+")"),false, false,null));
            }
            GroundLiteral maxTR = new GroundLiteral(new GroundPredicate("MAXTR(tag1|"+tag2+")"),false, false,null);
            rules.add(new GroundRegularRule(maxTR, max_r1r2t2_list, new MULTIMAX()));
            op1_r1r2t2_list.add(maxTR);
        }
        rules.add(new GroundRegularRule(op1_r1r2t2, op1_r1r2t2_list, op1));
        ArrayList<FaspFuzzyExpression> op2_r1r2t_list = new ArrayList<FaspFuzzyExpression>();
        op2_r1r2t_list.add(op1_r1r2t1); op2_r1r2t_list.add(op1_r1r2t2);
        rules.add(new GroundRegularRule(op2_r1r2t, op2_r1r2t_list, op2));
        /**RU**/
        ArrayList<FaspFuzzyExpression> op1_r1r2u1_list = new ArrayList<FaspFuzzyExpression>();
        for(String user1 : map_res_on_user.get(r1)){
            ArrayList<FaspFuzzyExpression> max_r1r2u1_list = new ArrayList<FaspFuzzyExpression>();
            for(String user2 : map_res_on_user.get(r2)){
                max_r1r2u1_list.add(new GroundLiteral(new GroundPredicate("SIMU("+user1+","+user2+")"),false, false,null));
            }
            GroundLiteral maxUR = new GroundLiteral(new GroundPredicate("MAXUR(user2|"+user1+")"),false, false,null);
            rules.add(new GroundRegularRule(maxUR, max_r1r2u1_list,new MULTIMAX()));
            op1_r1r2u1_list.add(maxUR);
        }
        rules.add(new GroundRegularRule(op1_r1r2u1, op1_r1r2u1_list, op1));
        ArrayList<FaspFuzzyExpression> op1_r1r2u2_list = new ArrayList<FaspFuzzyExpression>();
        for(String user2 : map_res_on_user.get(r2)){
            ArrayList<FaspFuzzyExpression> max_r1r2u2_list = new ArrayList<FaspFuzzyExpression>();
            for(String user1 : map_res_on_user.get(r1)){
                max_r1r2u2_list.add(new GroundLiteral(new GroundPredicate("SIMU("+user2+","+user1+")"),false, false,null));
            }
            GroundLiteral maxUR = new GroundLiteral(new GroundPredicate("MAXTR(user1|"+user2+")"),false, false,null);
            rules.add(new GroundRegularRule(maxUR, max_r1r2u2_list, new MULTIMAX()));
            op1_r1r2u2_list.add(maxUR);
        }
        rules.add(new GroundRegularRule(op1_r1r2u2, op1_r1r2u2_list, op1));
        ArrayList<FaspFuzzyExpression> op2_r1r2u_list = new ArrayList<FaspFuzzyExpression>();
        op2_r1r2u_list.add(op1_r1r2u1); op2_r1r2u_list.add(op1_r1r2u2);
        rules.add(new GroundRegularRule(op2_r1r2u, op2_r1r2u_list, op2));
        /**Rop3**/
        ArrayList<FaspFuzzyExpression> op3_r1r2_list = new ArrayList<FaspFuzzyExpression>();
        op3_r1r2_list.add(op2_r1r2u); op3_r1r2_list.add(op2_r1r2u);
        rules.add(new GroundRegularRule(r1r2, op3_r1r2_list, op3));
        rules.add(new GroundRegularRule(r2r1, op3_r1r2_list, op3));

        /*U*/
        String[] users = map_user_on_tag.keySet().toArray(new String[0]);
        for(int i=0; i< users.length; i++){
            for(int j=i+1; j< users.length; j++){
                /**UT**/
                ArrayList<FaspFuzzyExpression> op1_u1u2t1_list = new ArrayList<FaspFuzzyExpression>();
                for(String tag1 : map_user_on_tag.get(users[i])){
                    ArrayList<FaspFuzzyExpression> max_u1u2t1_list = new ArrayList<FaspFuzzyExpression>();
                    for(String tag2 : map_user_on_tag.get(users[j])){
                        max_u1u2t1_list.add(new GroundLiteral(new GroundPredicate("SIMT("+tag1+","+tag2+")"),false, false,null));
                    }
                    GroundLiteral maxTU = new GroundLiteral(new GroundPredicate("MAXTU(tag2|"+tag1+")"),false, false,null);
                    rules.add(new GroundRegularRule(maxTU, max_u1u2t1_list,new MULTIMAX()));
                    op1_u1u2t1_list.add(maxTU);
                }
                GroundLiteral op1_u1u2t1 = new GroundLiteral(new GroundPredicate("OP1U_tag1("+users[i]+","+users[j]+")"),false, false,null);
                rules.add(new GroundRegularRule(op1_u1u2t1, op1_u1u2t1_list, op1));
                ArrayList<FaspFuzzyExpression> op1_u1u2t2_list = new ArrayList<FaspFuzzyExpression>();
                for(String tag2 : map_user_on_tag.get(users[j])){
                    ArrayList<FaspFuzzyExpression> max_u1u2t2_list = new ArrayList<FaspFuzzyExpression>();
                    for(String tag1 : map_user_on_tag.get(users[i])){
                        max_u1u2t2_list.add(new GroundLiteral(new GroundPredicate("SIMT("+tag2+","+tag1+")"),false, false,null));
                    }
                    GroundLiteral maxTU = new GroundLiteral(new GroundPredicate("MAXTR(tag1|"+tag2+")"),false, false,null);
                    rules.add(new GroundRegularRule(maxTU, max_u1u2t2_list, new MULTIMAX()));
                    op1_u1u2t2_list.add(maxTU);
                }
                GroundLiteral op1_u1u2t2 = new GroundLiteral(new GroundPredicate("OP1U_tag2("+users[i]+","+users[j]+")"),false, false,null);
                rules.add(new GroundRegularRule(op1_u1u2t2, op1_u1u2t2_list, op1));
                ArrayList<FaspFuzzyExpression> op2_u1u2t_list = new ArrayList<FaspFuzzyExpression>();
                op2_u1u2t_list.add(op1_u1u2t1); op2_u1u2t_list.add(op1_u1u2t2);
                GroundLiteral op2_u1u2t = new GroundLiteral(new GroundPredicate("OP2U_tag("+users[i]+","+users[j]+")"),false, false,null);
                rules.add(new GroundRegularRule(op2_u1u2t, op2_u1u2t_list, op2));
                /**UR**/
                ArrayList<FaspFuzzyExpression> op1_u1u2r1_list = new ArrayList<FaspFuzzyExpression>();
                for(String res1 : map_user_on_res.get(users[i])){
                    ArrayList<FaspFuzzyExpression> max_u1u2r1_list = new ArrayList<FaspFuzzyExpression>();
                    for(String res2 : map_user_on_res.get(users[j])){
                        max_u1u2r1_list.add(new GroundLiteral(new GroundPredicate("SIMR("+res1+","+res2+")"),false, false,null));
                    }
                    GroundLiteral maxRU = new GroundLiteral(new GroundPredicate("MAXRU(res2|"+res1+")"),false, false,null);
                    rules.add(new GroundRegularRule(maxRU, max_u1u2r1_list,new MULTIMAX()));
                    op1_u1u2r1_list.add(maxRU);
                }
                GroundLiteral op1_u1u2r1 = new GroundLiteral(new GroundPredicate("OP1U_res1("+users[i]+","+users[j]+")"),false, false,null);
                rules.add(new GroundRegularRule(op1_u1u2r1, op1_u1u2r1_list, op1));
                ArrayList<FaspFuzzyExpression> op1_u1u2r2_list = new ArrayList<FaspFuzzyExpression>();
                for(String res2 : map_user_on_res.get(users[j])){
                    ArrayList<FaspFuzzyExpression> max_u1u2r2_list = new ArrayList<FaspFuzzyExpression>();
                    for(String res1 : map_user_on_res.get(users[i])){
                        max_u1u2r2_list.add(new GroundLiteral(new GroundPredicate("SIMR("+res2+","+res1+")"),false, false,null));
                    }
                    GroundLiteral maxRU = new GroundLiteral(new GroundPredicate("MAXRU(res1|"+res2+")"),false, false,null);
                    rules.add(new GroundRegularRule(maxRU, max_u1u2r2_list,new MULTIMAX()));
                    op1_u1u2r2_list.add(maxRU);
                }
                GroundLiteral op1_u1u2r2 = new GroundLiteral(new GroundPredicate("OP1U_res2("+users[i]+","+users[j]+")"),false, false,null);
                rules.add(new GroundRegularRule(op1_u1u2r1, op1_u1u2r1_list, op1));
                GroundLiteral op2_u1u2r = new GroundLiteral(new GroundPredicate("OP2U_res("+users[i]+","+users[j]+")"),false, false,null);
                ArrayList<FaspFuzzyExpression> op2_u1u2r_list = new ArrayList<FaspFuzzyExpression>();
                op2_u1u2r_list.add(op1_r1r2u1); op2_u1u2r_list.add(op1_u1u2r2);
                rules.add(new GroundRegularRule(op2_u1u2r, op2_u1u2r_list, op2));
                /**Uop3**/
                GroundLiteral op3_u1u2 = new GroundLiteral(new GroundPredicate("SIMU("+users[i]+","+users[j]+")"),false, false,null);
                GroundLiteral op3_u2u1 = new GroundLiteral(new GroundPredicate("SIMU("+users[j]+","+users[i]+")"),false, false,null);
                ArrayList<FaspFuzzyExpression> op3_u1u2_list = new ArrayList<FaspFuzzyExpression>();
                op3_u1u2_list.add(op2_u1u2t); op3_u1u2_list.add(op2_u1u2r);
                rules.add(new GroundRegularRule(op3_u1u2, op3_u1u2_list, op3));
                rules.add(new GroundRegularRule(op3_u2u1, op3_u1u2_list, op3));
            }
        }

        /*T*/
        String[] tags = map_tag_on_user.keySet().toArray(new String[0]);
        for(int i=0; i<tags.length; i++){
            for(int j=i+1; j< tags.length; j++){
                /**TU**/
                ArrayList<FaspFuzzyExpression> op1_t1t2u1_list = new ArrayList<FaspFuzzyExpression>();
                for(String user1 : map_tag_on_user.get(tags[i])){
                    ArrayList<FaspFuzzyExpression> max_t1t2u1_list = new ArrayList<FaspFuzzyExpression>();
                    for(String user2 : map_tag_on_user.get(tags[j])){
                        max_t1t2u1_list.add(new GroundLiteral(new GroundPredicate("SIMU("+user1+","+user2+")"),false, false,null));
                    }
                    GroundLiteral maxUT = new GroundLiteral(new GroundPredicate("MAXUT(user2|"+user1+")"),false, false,null);
                    rules.add(new GroundRegularRule(maxUT, max_t1t2u1_list,new MULTIMAX()));
                    op1_t1t2u1_list.add(maxUT);
                }
                GroundLiteral op1_t1t2u1 = new GroundLiteral(new GroundPredicate("OP1T_user1("+tags[i]+","+tags[j]+")"),false, false,null);
                rules.add(new GroundRegularRule(op1_t1t2u1, op1_t1t2u1_list, op1));
                ArrayList<FaspFuzzyExpression> op1_t1t2u2_list = new ArrayList<FaspFuzzyExpression>();
                for(String user2 : map_tag_on_user.get(tags[j])){
                    ArrayList<FaspFuzzyExpression> max_t1t2u2_list = new ArrayList<FaspFuzzyExpression>();
                    for(String user1 : map_tag_on_user.get(tags[i])){
                        max_t1t2u2_list.add(new GroundLiteral(new GroundPredicate("SIMU("+user2+","+user1+")"),false, false,null));
                    }
                    GroundLiteral maxUT = new GroundLiteral(new GroundPredicate("MAXUT(user1|"+user2+")"),false, false,null);
                    rules.add(new GroundRegularRule(maxUT, max_t1t2u2_list,new MULTIMAX()));
                    op1_t1t2u2_list.add(maxUT);
                }
                GroundLiteral op1_t1t2u2 = new GroundLiteral(new GroundPredicate("OP1T_user2("+tags[i]+","+tags[j]+")"),false, false,null);
                rules.add(new GroundRegularRule(op1_t1t2u2, op1_t1t2u2_list, op1));
                ArrayList<FaspFuzzyExpression> op2_t1t2u_list = new ArrayList<FaspFuzzyExpression>();
                op2_t1t2u_list.add(op1_t1t2u1); op2_t1t2u_list.add(op1_t1t2u2);
                GroundLiteral op2_t1t2u = new GroundLiteral(new GroundPredicate("OP2T_user("+tags[i]+","+tags[j]+")"),false, false,null);
                rules.add(new GroundRegularRule(op2_t1t2u, op2_t1t2u_list, op2));
                /**TR**/
                ArrayList<FaspFuzzyExpression> op1_t1t2r1_list = new ArrayList<FaspFuzzyExpression>();
                for(String res1 : map_tag_on_res.get(tags[i])){
                    ArrayList<FaspFuzzyExpression> max_t1t2r1_list = new ArrayList<FaspFuzzyExpression>();
                    for(String res2 : map_tag_on_res.get(tags[j])){
                        max_t1t2r1_list.add(new GroundLiteral(new GroundPredicate("SIMR("+res1+","+res2+")"),false, false,null));
                    }
                    GroundLiteral maxUR = new GroundLiteral(new GroundPredicate("MAXUR(res2|"+res1+")"),false, false,null);
                    rules.add(new GroundRegularRule(maxUR, max_t1t2r1_list,new MULTIMAX()));
                    op1_t1t2r1_list.add(maxUR);
                }
                GroundLiteral op1_t1t2r1 = new GroundLiteral(new GroundPredicate("OP1T_res1("+tags[i]+","+tags[j]+")"),false, false,null);
                rules.add(new GroundRegularRule(op1_t1t2r1, op1_t1t2r1_list, op1));
                ArrayList<FaspFuzzyExpression> op1_t1t2r2_list = new ArrayList<FaspFuzzyExpression>();
                for(String res2 : map_tag_on_res.get(tags[j])){
                    ArrayList<FaspFuzzyExpression> max_t1t2r2_list = new ArrayList<FaspFuzzyExpression>();
                    for(String res1 : map_tag_on_res.get(tags[i])){
                        max_t1t2r2_list.add(new GroundLiteral(new GroundPredicate("SIMR("+res2+","+res1+")"),false, false,null));
                    }
                    GroundLiteral maxUR = new GroundLiteral(new GroundPredicate("MAXUR(res1|"+res2+")"),false, false,null);
                    rules.add(new GroundRegularRule(maxUR, max_t1t2r2_list,new MULTIMAX()));
                    op1_t1t2r2_list.add(maxUR);
                }
                GroundLiteral op1_t1t2r2 = new GroundLiteral(new GroundPredicate("OP1T_res2("+tags[i]+","+tags[j]+")"),false, false,null);
                rules.add(new GroundRegularRule(op1_t1t2r2, op1_t1t2r2_list, op1));
                ArrayList<FaspFuzzyExpression> op2_t1t2r_list = new ArrayList<FaspFuzzyExpression>();
                op2_t1t2r_list.add(op1_t1t2r1); op2_t1t2r_list.add(op1_t1t2r2);
                GroundLiteral op2_t1t2r = new GroundLiteral(new GroundPredicate("OP2T_res("+tags[i]+","+tags[j]+")"),false, false,null);
                rules.add(new GroundRegularRule(op2_t1t2r, op2_t1t2r_list, op2));
                /**Top3**/
                GroundLiteral op3_t1t2 = new GroundLiteral(new GroundPredicate("SIMT("+tags[i]+","+tags[j]+")"),false, false,null);
                GroundLiteral op3_t2t1 = new GroundLiteral(new GroundPredicate("SIMT("+tags[j]+","+tags[i]+")"),false, false,null);
                ArrayList<FaspFuzzyExpression> op3_t1t2_list = new ArrayList<FaspFuzzyExpression>();
                op3_t1t2_list.add(op2_t1t2u); op3_t1t2_list.add(op2_t1t2r);
                rules.add(new GroundRegularRule(op3_t1t2, op3_t1t2_list, op3));
                rules.add(new GroundRegularRule(op3_t2t1, op3_t1t2_list, op3));
            }
View Full Code Here

TOP

Related Classes of fasp.datatypes.GroundLiteral

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.