/** * Returns if the classifier of the class is equal to the classifier given as a parameter. * * @param cl is a classifier. * @return a boolean indicating if they are equals. */ public boolean equals(Classifier cl) { try { if (rep.getAction() != cl.rep.getAction()) return false; return rep.equals(cl.rep); } catch (Exception e) { return false; } } // end equals
/** * Returns if the classifier of the class subsumes the classifier passed as a parameter. * * @param cl is the subsumed classifier. * @return a boolean indicating if it subsumes */ public boolean doesSubsume(Classifier cl) { if (rep.getAction() != cl.rep.getAction()) return false; if (parameters.couldSubsume()) { if (rep.isMoreGeneral(cl.rep)) { return true; } } return false; } // end doesSubsume
/** * Performs a test by sending HTTP Gets to the URL, and records the number of bytes returned. Each * test results are documented and displayed in standard out with the following information: * * <p>URL - The source URL of the test REQ CNT - How many times this test has run START - The * start time of the last test run STOP - The stop time of the last test run THREAD - The thread * id handling this test case RESULT - The result of the test. Either the number of bytes returned * or an error message. */ private void doTest() { String result = ""; this.reqCount++; // Connect and run test steps Date startTime = new Date(); try { ClientResource client = new ClientResource(this.myURL); // place order JSONObject json = new JSONObject(); json.put("payment", "quarter"); json.put("action", "place-order"); client.post(new JsonRepresentation(json), MediaType.APPLICATION_JSON); // Get Gumball Count Representation result_string = client.get(); JSONObject json_count = new JSONObject(result_string.getText()); result = Integer.toString((int) json_count.get("count")); } catch (Exception e) { result = e.toString(); } finally { Date stopTime = new Date(); // Print Report of Result: System.out.println( "======================================\n" + "URL => " + this.myURL + "\n" + "REQ CNT => " + this.reqCount + "\n" + "START => " + startTime + "\n" + "STOP => " + stopTime + "\n" + "THREAD => " + Thread.currentThread().getName() + "\n" + "RESULT => " + result + "\n"); } }
/** * Indicate if the current representation is more general than the representation passed as a * parameter. * * @param r is the representation to which the current representation is compared. * @return a boolean indicating if the current representation is more general. */ public boolean isMoreGeneral(Representation r) { boolean ret = false; // We need to check the condition for the "insertInPSubsumingCl if (action != r.action) return false; if (numberOfDontCareSymbols() >= r.numberOfDontCareSymbols()) { for (int i = 0; i < rep.length; i++) { if (!rep[i].isMoreGeneral(r.rep[i])) return false; } return true; } return false; }
/** * Prints the desnormalized classifier to the specified file. * * @param fout is the file output where the classifier has to be printed. */ public void printNotNorm(PrintWriter fout) { rep.printNotNorm(fout); if (parameters != null) parameters.print(fout); }
/** Prints the classifier. */ public void print() { rep.print(); if (parameters != null) parameters.print(); }
/** * Indicates if the classifier is more general than the classifier passed as a parameter. * * @param cl is the classifier to which the current classifier is compared. * @return a boolean indicating if the current classifier is more general */ public boolean isMoreGeneral(Classifier cl) { return rep.isMoreGeneral(cl.rep); }
/** * Returns the number of don't care symbols in the classifier. It is used by the action set * subsumption * * @return a double with the number of don't care symbols. */ public double numberOfDontCareSymbols() { return rep.numberOfDontCareSymbols(); }
/** * Changes all the don't care symbols by the state in the environment, with Pspecify probability * * @param env is the environment. */ public void makeSpecify(double[] env) { rep.makeSpecify(env); }
/** * Indicates if the classifier matches with the environmental state * * @param envState is the environment state * @return a boolean indicating if the classifier matches. */ public boolean match(double[] envState) { return rep.match(envState); } // end match
/** * Returns the action of the classifier * * @return an integer with the action of the classifier */ public int getAction() { return rep.getAction(); } // end getAction
/** * sets the allele value * * @param i is the position. * @param cl is the classifier that has to be copied. */ public void setAllele(int i, Classifier cl) { rep.setAllele(i, cl.rep); } // end setAllele
/** * Sets the allele value * * @param i is the position. * @param lowerValue is the lower value that has to be set. * @param upperValue is the upper value that has to be set. */ public void setAllele(int i, double lowerValue, double upperValue) { rep.setAllele(i, lowerValue, upperValue); } // end setAllele
/** * It crosses a real allele within two parents. If the representation is a ternary representation, * a crossover within intervals is not possible because there is only one gene in each position. * So, in this case, the gene of the second parent will be copied. In case of being a real * representation, a random number is generated to decide where to cross the interval. It it's * crossed within the inteval, the crossAllele method will do it. * * @param parent1 is the first parent classifier. * @param parent2 is the second parent classifier. */ public void crossAllele(int i, Classifier parent1, Classifier parent2) { rep.crossAllele(i, parent1.rep, parent2.rep); } // end crossAllele
/** * It draws the population to a file. A character allele is drawn as 1 o 0. Otherwise, a real * allele is drawn in ten points, which represent the interval [0..1] divided in ten fragments. In * each fragment, there can be three types of symbols: . --> The fragment is not covered by the * classifier. o --> The fragment is partially covered by the classifier. O --> The fragment is * totally covered by the classifier. * * <p>This notation has been got from Wilson2000 XCSR * * @param fout is the file where the population has to be drawn. */ public void draw(PrintWriter fout) { rep.draw(fout); } // end draw
/** * It constructs a classifier with the condition and the action specified. It's used by the * covering operator. * * <p> * * @param condition is the environtment state * @param action is the action chosen * @param size is the size of the set. * @param tStamp is the time */ public Classifier(double[] condition, int action, int size, int tStamp) { rep = new Representation(condition, action); parameters = new Parameters(tStamp, size, rep.getGenerality()); } // end Classifier
/** * Sets the action passed to the classifier * * @param act is the action to be set. */ public void setAction(int act) { rep.setAction(act); } // end setAction
/** * Computes the generality of the classifier. Its result is stored in the generality parameter. */ public void calculateGenerality() { parameters.setGenerality(rep.getGenerality()); } // end calculateGenerality
/** * Mutates the classifier. It mutates the action and the condition. * * @param envState is the current environtment state. It is necessary for the niched mutation. * @return a boolean indicating if the action has been mutated. */ public boolean mutate(double[] envState) { return rep.mutate(envState); } // end mutate