/** *********************************************** */
  public void init() {
    mvl = new Line(0, 0, 0, h);
    mvl.setStrokeWidth(1);
    mvl.setStroke(Color.RED);
    mhl = new Line(0, 0, w, 0);
    mhl.setStrokeWidth(1);
    mhl.setStroke(Color.BLUE);
    TargetPoint = new Circle(5);
    TargetPoint.setFill(Color.CADETBLUE);
    drawPane.getChildren().add(TargetPoint);

    Line vl = new Line(w / 2, 0, w / 2, h);
    vl.setStrokeWidth(0.2);
    Line hl = new Line(0, h / 2, w, h / 2);
    vl.setStrokeWidth(0.2);
    robot = new robot(35, 45);
    robot.setSpeed(0);
    robot.get().setFill(Color.BROWN);
    robot.get().setStroke(Color.BLACK);
    robot.setTranslateX((w - 35) / 2);
    robot.setTranslateY(h - 90);
    drawPane.getChildren().addAll(mhl, mvl, hl, vl, robot);
    Algorithm.setRobot(robot);
    Algorithm.setSpeed(0);
    Static.RoboTC = RoboTC;
    Static.RobotS = RobotS;
    Static.RobotR = RobotR;
    Static.SensorDR = SensorDR;
    Static.SensorDL = SensorDL;
  }
  public static void main(String[] args) {

    try {
      Scanner scanner = new Scanner(new FileInputStream(new File("input.txt")));
      int n = scanner.nextInt();
      // System.out.println("n = " + n);
      while (n != 0) {
        int m = (int) (scanner.nextDouble() * 100);
        // System.out.println("m = " + m);
        Candy[] array = new Candy[n + 1];
        array[0] = new Candy(0, 0);
        for (int i = 1; i <= n; i++) {
          array[i] = new Candy(scanner.nextInt(), (int) (scanner.nextDouble() * 100));
          // System.out.printf("%d %d %n",array[i].GetCalories(),array[i].GetPrice());
        }
        Algorithm solution = new Algorithm(array, n, (int) m);
        int output = solution.SolveIt();
        System.out.println(output);
        n = scanner.nextInt();
        // System.out.println("n = " + n);
      }
      scanner.close();
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
 /**
  * Crea una tabella sull'output out, per tutti i generi di sequenze, eseguendo tutti gli algoritmi
  * su array di lunghezze via via crescenti, da step fino a maxLength
  */
 static void makeTable(EnumSet<Algorithm> algorithms, int step, int maxLength, String fileName)
     throws IOException {
   ;
   FileWriter outFile = new FileWriter(fileName, false);
   PrintWriter writer = new PrintWriter(outFile);
   writer.println("sep=;");
   writer.println(
       "Test a on a int array: "
           + getProperty("os.name")
           + " Java "
           + getProperty("java.version"));
   for (SequenceKind kind : SequenceKind.values()) {
     writer.println(kind.toString());
     System.out.println(kind.toString() + "\n");
     for (Algorithm algo : algorithms) writer.print(";" + algo.toString());
     writer.println();
     for (int len = step; len <= maxLength; len += step) {
       runAllAlgorithms(algorithms, kind, writer, len);
     }
     writer.println();
   }
   writer.close();
   System.out.println();
   System.out.println();
 }
 public String createAuthenticationHeader(
     AuthenticationChallenge challenge, String userName, String password) {
   StringBuffer sb = new StringBuffer("Digest ");
   Algorithm algorithm = new Algorithm();
   algorithm.appendParams(sb, challenge, userName, password);
   return sb.toString();
 }
예제 #5
0
  public static void main(String[] args) {
    String folder = "PresidentialDebate"; // set the path to the data with io.DataPath and folder
    AppletConf apConf = new AppletConf(640, 480, 255); // cloud width, height and bk color

    StormConf conf = new StormConf(); // Storm Parameters
    conf.maxFiles = -1;
    conf.maxWords = 25;
    //		conf.rSeed = 12345;
    conf.tfIdf = 0;
    conf.coorColorer = 0;
    conf.coorAngler = 0;
    conf.coorPlacer = 0;
    conf.tol = -1;

    Loader load = new FileLoader(conf.maxFiles, folder);
    //		new FileLoaderWeight(conf.maxFiles, folder);
    Algorithm f;
    if (conf.coorPlacer <= 1) f = new Iterative(load, apConf, conf);
    else if (conf.coorPlacer == 3) f = new Force(load, apConf, conf);
    else f = new Combined(load, apConf, conf);
    f.init();
    f.initProcess();
    HTMLSaver.singleStorm(load, conf, apConf);
    SVGSaver.singleStorm(load, conf, apConf, f);
  }
예제 #6
0
파일: Main.java 프로젝트: RubelAhmed57/KEEL
  /**
   * It launches the algorithm
   *
   * @param confFile String it is the filename of the configuration file.
   */
  public void execute(String confFile) {
    parameters = new parseParameters();
    parameters.parseConfigurationFile(confFile);

    Algorithm method = new Algorithm(parameters);

    method.execute();
  }
예제 #7
0
파일: Encrypter.java 프로젝트: ggdio/superj
 /**
  * Defines the algorithm type
  *
  * @param type - {@link Algorithm} to be used(e.g: MD5, SHA, ...)
  */
 private void setType(Algorithm type) {
   if (type == null) {
     log.warn(
         "The algorithm cannot be null...setting a default type - " + defaultType.algorithm());
     type = defaultType;
   }
   this.type = type;
   log.debug("Established '" + type.algorithm().toUpperCase() + "' for the encryption");
 }
예제 #8
0
 public static void main(String argv[]) {
   Design des = null;
   try {
     des = new Design(argv[0]);
   } catch (Exception ex) {
     error(ex);
   }
   Algorithm algo = new DefaultAlgorithm(des);
   algo.getInitialPackingTree();
 }
예제 #9
0
  public static Algorithm getCompressionAlgorithmByName(String compressName) {
    Algorithm[] algos = Algorithm.class.getEnumConstants();

    for (Algorithm a : algos) {
      if (a.getName().equals(compressName)) {
        return a;
      }
    }

    throw new IllegalArgumentException("Unsupported compression algorithm name: " + compressName);
  }
예제 #10
0
  /**
   * Get names of supported compression algorithms.
   *
   * @return Array of strings, each represents a supported compression algorithm. Currently, the
   *     following compression algorithms are supported.
   */
  public static String[] getSupportedAlgorithms() {
    Algorithm[] algos = Algorithm.class.getEnumConstants();

    String[] ret = new String[algos.length];
    int i = 0;
    for (Algorithm a : algos) {
      ret[i++] = a.getName();
    }

    return ret;
  }
 public static void main(String[] args) {
   Algorithm algorithm =
       AlgorithmFactory.getAlgorithm(AlgorithmFactory.AlgorithmType.SHORTEST_PATH);
   if (algorithm != null) {
     algorithm.solveProblem();
   }
   algorithm = AlgorithmFactory.getAlgorithm(AlgorithmFactory.AlgorithmType.SPANNING_TREE);
   if (algorithm != null) {
     algorithm.solveProblem();
   }
 }
예제 #12
0
 public static void oneCompany(String Symbol) {
   Double[] close;
   close = CSV_Parser.getClose(Symbol);
   int i = 0;
   /*while(i<close.length)
   {
   	System.out.println(close[i]);
   	++i;
   }*/
   Algorithm.HeadAndShoulders(close);
   Algorithm.InverseHeadAndShoulders(close);
   Algorithm.DoubleTops(close);
 }
예제 #13
0
 private static void printResult(List<Point> pointList, List<Algorithm> algorithms) {
   for (Algorithm algorithm : algorithms) {
     Result r = algorithm.run(pointList);
     r.stop();
     System.err.println(algorithm.toString());
     System.err.println("Time: " + r.getTime());
     System.err.println("Iterations: " + r.getIterationCount());
     for (RoundResult rr : r.getResultsToReport()) {
       System.err.println(rr.printResult());
     }
     //            System.out.println(r.getBestResult().print(true));
     System.err.println();
   }
 }
예제 #14
0
파일: Encrypter.java 프로젝트: ggdio/superj
 /**
  * Initialize the encryption system
  *
  * @param type - {@link Algorithm} to be used(e.g: MD5, SHA, ...)
  */
 public Encrypter(Algorithm type) throws NoSuchAlgorithmException {
   log.debug("Initializing the encrypter");
   setType(type);
   try {
     digest = MessageDigest.getInstance(type.algorithm());
   } catch (NoSuchAlgorithmException e) {
     log.warn(
         "The "
             + type.algorithm()
             + " algorithm is not available on current system...setting a default type - "
             + defaultType.algorithm(),
         e);
     digest = MessageDigest.getInstance(defaultType.algorithm());
   }
 }
예제 #15
0
 @Override
 protected void play() {
   final State initial_state = getInitialState();
   // Move move = minimaxDecision(initial_state);
   try {
     Move move;
     if (algorithm.equals(Algorithm.ALPHABETA)) {
       move = AIAlgorithm.alphaBetaSearch(initial_state);
     } else {
       move = AIAlgorithm.minimaxSearch(initial_state);
     }
     final IGridPlayDelegate playDel = (IGridPlayDelegate) getPlayerBridge().getRemoteDelegate();
     final PlayerID me = getPlayerID();
     final Territory start =
         getGameData()
             .getMap()
             .getTerritoryFromCoordinates(move.getStart().getFirst(), move.getStart().getSecond());
     final Territory end =
         getGameData()
             .getMap()
             .getTerritoryFromCoordinates(move.getEnd().getFirst(), move.getEnd().getSecond());
     final IGridPlayData play = new GridPlayData(start, end, me);
     playDel.play(play);
   } catch (final OutOfMemoryError e) {
     System.out.println(
         "Ran out of memory while searching for next move: " + counter + " moves examined.");
     System.exit(-1);
   }
 }
 /*
  * (non-Javadoc)
  *
  * @see org.graphstream.stream.SinkAdapter#stepBegins(java.lang.String,
  * long, double)
  */
 public void stepBegins(String sourceId, long timeId, double step) {
   switch (mode) {
     case BY_STEP:
       algo.compute();
       break;
   }
 }
예제 #17
0
 public void dispose() {
   inputSignal = null;
   if (algorithm != null) {
     algorithm.dispose();
     algorithm = null;
   }
 }
예제 #18
0
  /**
   * The business logic of this selector for use as ResourceSelector of FileSelector.
   *
   * @param basedir as described in BaseExtendSelector
   * @param filename as described in BaseExtendSelector
   * @param cacheKey the name for the key for storing the hashvalue
   * @return
   */
  private boolean isSelected(File basedir, String filename, String cacheKey) {
    validate();
    File f = new File(basedir, filename);

    // You can not compute a value for a directory
    if (f.isDirectory()) {
      return selectDirectories;
    }

    // Get the values and do the comparison
    String cachedValue = String.valueOf(cache.get(f.getAbsolutePath()));
    String newValue = algorithm.getValue(f);

    boolean rv = (comparator.compare(cachedValue, newValue) != 0);

    // Maybe update the cache
    if (update && rv) {
      cache.put(f.getAbsolutePath(), newValue);
      setModified(getModified() + 1);
      if (!getDelayUpdate()) {
        saveCache();
      }
    }

    return rv;
  }
 @Override
 public double getPercentageCompleted(Algorithm algorithm) {
   if (iteration == algorithm.getIterations()) {
     return 0.0;
   } else {
     return 1.0;
   }
 }
예제 #20
0
  public static void main(String[] args) throws JMException, ClassNotFoundException {
    Problem problem; // The problem to solve
    Algorithm algorithm; // The algorithm to use
    Operator crossover; // Crossover operator
    Operator mutation; // Mutation operator
    Operator selection; // Selection operator

    // int bits ; // Length of bit string in the OneMax problem

    // bits = 512 ;
    // problem = new OneMax(bits);

    problem = new Sphere("Real", 20);
    // problem = new Easom("Real") ;
    // problem = new Griewank("Real", 10) ;

    algorithm = new DE(problem); // Asynchronous cGA

    /* Algorithm parameters*/
    algorithm.setInputParameter("populationSize", 100);
    algorithm.setInputParameter("maxEvaluations", 1000000);

    // Crossover operator
    crossover = CrossoverFactory.getCrossoverOperator("DifferentialEvolutionCrossover");
    crossover.setParameter("CR", 0.1);
    crossover.setParameter("F", 0.5);
    crossover.setParameter("DE_VARIANT", "rand/1/bin");

    // Add the operators to the algorithm
    selection = SelectionFactory.getSelectionOperator("DifferentialEvolutionSelection");

    algorithm.addOperator("crossover", crossover);
    algorithm.addOperator("selection", selection);

    /* Execute the Algorithm */
    long initTime = System.currentTimeMillis();
    SolutionSet population = algorithm.execute();
    long estimatedTime = System.currentTimeMillis() - initTime;
    System.out.println("Total execution time: " + estimatedTime);

    /* Log messages */
    System.out.println("Objectives values have been writen to file FUN");
    population.printObjectivesToFile("FUN");
    System.out.println("Variables values have been writen to file VAR");
    population.printVariablesToFile("VAR");
  } // main
예제 #21
0
 /** Add an algorithm at the given deduction step. */
 void addAlgo(Algorithm a, int step) {
   algos.add(a);
   try {
     updateComplexity(a.getComplexity(), step);
   } catch (ComplexityClashException e) {
     System.err.println(
         "Complexity clash for " + problem.getName() + " on " + node + " " + a + " and " + algos);
   }
 }
 private AlgorithmStatus run0(ReachedSet reached, Algorithm algorithm)
     throws InterruptedException, CPAException, CPAEnabledAnalysisPropertyViolationException {
   logger.log(Level.INFO, "Starting sub-analysis");
   shutdownNotifier.shutdownIfNecessary();
   AlgorithmStatus status = algorithm.run(reached);
   shutdownNotifier.shutdownIfNecessary();
   logger.log(Level.INFO, "Finished sub-analysis");
   return status;
 }
  /** ********************************************************** */
  public void setObstacles() {
    drawPane.setOnMouseClicked(
        e -> {
          if (Init) {
            object obj = new object(33, 33);
            obj.get().setX(e.getX());
            obj.get().setY(e.getY());
            obj.get().setFill(new Color(0.1, 0.1, 0.7, 0.5));
            obj.setSpeed(3);
            drawPane.getChildren().add(obj);
            Algorithm.add(obj);
          } else {
            TargetPoint.setCenterX(e.getX());
            TargetPoint.setCenterY(e.getY());

            Algorithm.setTarget(e.getX(), e.getY());
          }
        });
  }
예제 #24
0
  public static void main(String[] args) {
    ExampleFitness func = new ExampleFitness();
    Algorithm algo = new Algorithm(new ExampleCrossover(func), func);
    algo.setMaxIter(10);
    algo.setMinValue(-100);
    algo.setMaxValue(100);
    algo.setMutationProbability(0.01D);
    algo.setStartPopulation(10);
    algo.setSelection(2);

    algo.go();
  }
예제 #25
0
  @Test
  public void testDaraQueryServices() throws IOException {
    Execution execution = new Execution();
    SearchQuery searchQuery = postDoiQuery("?q=title:ALLBUS");
    execution.setSearchQuery(searchQuery.getUri());
    execution.addQueryServiceClasses(DaraHTMLQueryService.class);
    execution.setAlgorithm(FederatedSearcher.class);
    Algorithm algo =
        execution.instantiateAlgorithm(
            dataStoreClient, dataStoreClient, fileResolver, fileResolver);
    algo.run();

    List<SearchResult> sr = dataStoreClient.get(SearchResult.class, execution.getSearchResults());

    // be careful, could change from time to time
    Assert.assertEquals("Anomie (ALLBUS)", sr.get(0).getTitles().get(0));
    Assert.assertEquals("10.6102/zis58", sr.get(0).getIdentifier());
    Assert.assertEquals(0, sr.get(0).getListIndex());
  }
예제 #26
0
 /** Override toString() method of parent class. */
 public String toString() {
   String result = "";
   result += "<algorithm_input signal=\"";
   if (inputSignal != null) result += inputSignal.getShortName();
   else result += "null";
   result += "\" algorithm=\"";
   if (algorithm != null) result += algorithm.getName();
   else result += "null";
   result += "\" />";
   return result;
 }
  /**
   * Crea una riga della tabella sull'output out, per sequenze di genere kind, eseguendo tutti gli
   * algoritmi algorithms, su un array di lunghezza len
   */
  static void runAllAlgorithms(
      EnumSet<Algorithm> algorithms, SequenceKind kind, PrintWriter out, int len) {
    int maxValue = (kind == SequenceKind.REPEATED_VALUES) ? len / 3 : 9 * len / 10;
    int[] array = naturalRandomArray(len, maxValue);
    if (kind == SequenceKind.ALMOST_SORTED) {
      Arrays.sort(array);
      swap(array, len / 3, 2 * len / 3);
    }

    out.printf("%6d;", len);
    System.out.println(len);
    for (Algorithm algo : algorithms) {
      System.out.println(algo.toString());
      int[] arrayCopy = Arrays.copyOf(array, array.length);
      double time = executionTime(algo, arrayCopy);
      out.printf("%9.2f;", time);
    }
    out.println();
    System.out.println();
  }
 public void reset() {
   super.reset();
   system.reset();
   if (s != null) {
     for (int i = 0; i < numberOfSubstances; i++) {
       s[i].storeValue();
       s[i].storeRate();
     }
     timer.storeTimePoint();
   }
 }
예제 #29
0
 /** Overrides BaseSelector.verifySettings(). */
 public void verifySettings() {
   configure();
   if (cache == null) {
     setError("Cache must be set.");
   } else if (algorithm == null) {
     setError("Algorithm must be set.");
   } else if (!cache.isValid()) {
     setError("Cache must be proper configured.");
   } else if (!algorithm.isValid()) {
     setError("Algorithm must be proper configured.");
   }
 }
예제 #30
0
  @Override
  public void setup(Topology topology, TaskDistribution td, Agent agent) {
    this.topology = topology;
    this.td = td;
    this.agent = agent;

    // initialize the planner
    int capacity = agent.vehicles().get(0).capacity();
    String algorithmName = agent.readProperty("algorithm", String.class, "ASTAR");

    // Throws IllegalArgumentException if algorithm is unknown
    algorithm = Algorithm.valueOf(algorithmName.toUpperCase());
  }