public static void main(String[] args) { String s = "5*Toke*10"; Hashtable<String, Double> Ov = new Hashtable(); Ov.put("Toke", 10.0); Tokenizer myToken = new Tokenizer(s); IntoPost ITP = new IntoPost(myToken); TheQueue<String> The = ITP.translate(); Evaluate Eval = new Evaluate(The); double x = Eval.evaluate(Ov); System.out.println(x); }
/* * (non-Javadoc) * * @see java.lang.Runnable#run() */ public void run() { // Do not run something terminated if (isTerminated()) return; logger.info("Run optimizer"); generation = 0; while (!isTerminated()) { pauseLock.lock(); try { while (isPaused) unpaused.await(); if (isTerminated) return; } catch (InterruptedException ie) { // Finish return; } finally { pauseLock.unlock(); } // // Initialise the population with a dummy individual // if (population.isEmpty()) { Solution solution = new Solution(); for (Node_Variable variable : request.variables()) solution.add(new Binding(variable, Node.NULL)); population.add(solution); } // Increment the generation counter ++generation; // // Generate a new set of offspring and copy the parents into it // first // // logger.info("Generate"); Set<Solution> newPopulation = new HashSet<Solution>(); newPopulation.addAll(population); // Add the parents generateOp.createPopulation(population, newPopulation); // // Evaluate all of them // // logger.info("Evaluate " + newPopulation.size()); // Counts the number of different solutions evaluationsCounter += newPopulation.size() - population.size(); evaluateOp.evaluatePopulation(newPopulation); /* * String buffer = "Fitnesses "; for (Solution s : newPopulation) * buffer += s.getFitness() + " "; logger.info(buffer); */ // Provide feed back to the generation operator generateOp.updateProviderRewards(newPopulation); // // Get rid of the previous population and insert the kids // // logger.info("Cut"); population.clear(); population.addAll(newPopulation); while (population.size() > POPULATION_SIZE) population.remove(population.first()); // // Track for optimality // double topFitness = population.last().getFitness(); for (Solution s : population) { // Increment age if (s.getFitness() != topFitness) s.resetAge(); s.incrementAge(); // Check optimality s.setOptimal(false); if (s.getAge() >= MAXIMUM_GENERATION && s.getFitness() > 0) s.setOptimal(true); if (s.getFitness() == 1.0d) s.setOptimal(true); // If the solution is optimal add its (valid!) triples to the // black // list if (s.isOptimal()) { synchronized (blackListedTriples) { blackListedTriples.addAll(request.getTripleSet(s)); } } // Print solution // logger.info(s.toString()); } logger.info("Generation " + generation + ", best fitness=" + topFitness); for (Solution s : population) logger.info(s.toString()); // // Notify observers that a loop has been done // setChanged(); notifyObservers(population); // for (Solution s : population) // if (s.isOptimal()) // this.terminate(); // // Wait a bit for the data layer // datalayer.waitForLatencyBuffer(); // // Remove all optimum individuals from the population // List<Solution> toRemove = new ArrayList<Solution>(); for (Solution s : population) if (s.isOptimal()) toRemove.add(s); population.removeAll(toRemove); } }