@@ -0,0 +1,3419 @@
+package org.avmframework.examples;%0A%0Aimport org.apache.commons.math3.random.MersenneTwister;%0Aimport org.apache.commons.math3.random.RandomGenerator;%0Aimport org.avmframework.AlternatingVariableMethod;%0Aimport org.avmframework.Monitor;%0Aimport org.avmframework.TerminationPolicy;%0Aimport org.avmframework.Vector;%0Aimport org.avmframework.examples.util.ArgsParser;%0Aimport org.avmframework.initialization.Initializer;%0Aimport org.avmframework.initialization.RandomInitializer;%0Aimport org.avmframework.localsearch.LocalSearch;%0Aimport org.avmframework.objective.NumericObjectiveValue;%0Aimport org.avmframework.objective.ObjectiveFunction;%0Aimport org.avmframework.objective.ObjectiveValue;%0Aimport org.avmframework.variable.IntegerVariable;%0Aimport org.avmframework.variable.Variable;%0A%0Apublic class OneMax %7B%0A%0A  // HOW TO RUN:%0A  //%0A  // java class org.avmframework.examples.OneMax %5Bsearch%5D%0A  //   where:%0A  //     - %5Bsearch%5D is an optional parameter denoting which search to use%0A  //       (e.g., %22IteratedPatternSearch%22, %22GeometricSearch%22 or %22LatticeSearch%22)%0A%0A  // CHANGE THE FOLLOWING CONSTANTS TO EXPLORE THEIR EFFECT ON THE SEARCH:%0A%0A  // - vector constants%0A  static final int NUM_VARS = 10;%0A  static final int INIT = 0;%0A  static final int MIN = -100000;%0A  static final int MAX = 100000;%0A%0A  // - search constants%0A  static final String SEARCH_NAME = %22IteratedPatternSearch%22; // can also be set at the command line%0A  static final int MAX_EVALUATIONS = 1000;%0A%0A  public static void main(String%5B%5D args) %7B%0A%0A    // define the objective function%0A    ObjectiveFunction objFun =%0A        new ObjectiveFunction() %7B%0A          @Override%0A          protected ObjectiveValue computeObjectiveValue(Vector vector) %7B%0A            int distance = 0;%0A            for (Variable var : vector.getVariables()) %7B%0A              distance += Math.abs(((IntegerVariable) var).getValue());%0A            %7D%0A            return NumericObjectiveValue.lowerIsBetterObjectiveValue(distance, 1);%0A          %7D%0A        %7D;%0A%0A    // set up the vector to be optimized%0A    Vector vector = new Vector();%0A    for (int i = 0; i %3C NUM_VARS; i++) %7B%0A      vector.addVariable(new IntegerVariable(INIT, MIN, MAX));%0A    %7D%0A%0A    // instantiate local search from command line, using default (set by the constant SEARCH_NAME)%0A    // if none supplied%0A    LocalSearch localSearch = new ArgsParser(OneMax.class, args).parseSearchParam(SEARCH_NAME);%0A%0A    // set up the termination policy%0A    TerminationPolicy terminationPolicy =%0A        TerminationPolicy.createMaxEvaluationsTerminationPolicy(MAX_EVALUATIONS);%0A%0A    // set up random initialization of vectors%0A    RandomGenerator randomGenerator = new MersenneTwister();%0A    Initializer initializer = new RandomInitializer(randomGenerator);%0A%0A    // set up the AlternatingVariableMethod%0A    AlternatingVariableMethod avm = new AlternatingVariableMethod(%0A        localSearch, terminationPolicy, initializer);%0A%0A    // perform the search%0A    Monitor monitor = avm.search(vector, objFun);%0A%0A    // output the results%0A    System.out.println(%22Best solution: %22 + monitor.getBestVector());%0A    System.out.println(%22Best objective value: %22 + monitor.getBestObjVal());%0A    System.out.println(%0A        %22Number of objective function evaluations: %22%0A            + monitor.getNumEvaluations()%0A            + %22 (unique: %22%0A            + monitor.getNumUniqueEvaluations()%0A            + %22)%22);%0A    System.out.println(%22Running time: %22 + monitor.getRunningTime() + %22ms%22);%0A  %7D%0A%7D%0A

Add OneMax example