/*------------------------------------------------------------- Copyright (C) 2000 Peter Clote, Sebastian Will. All Rights Reserved. written by Peter Clote modified by Sebastian Will Permission to use, copy, modify, and distribute this software and its documentation for NON-COMMERCIAL purposes and without fee is hereby granted provided that this copyright notice appears in all copies. THE AUTHOR AND PUBLISHER MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHORS AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. -------------------------------------------------------------*/ /*----------------------------------- MonteCarlo P. Clote, Feb 1999 This class implements a MonteCarlo algorithm with simulated annealing, in order to determine the minimum of a function f : {0,1,2,...,2^n-1} ---> Reals where n = NumBits, a constant. -------------------------------------*/ class MonteCarlo { static final int NumBits = 7; static final int MAX = (int) Math.pow(2,NumBits); // equals 2^NumBits /*-------------------------------- F is the function, whose minimum we want to compute. This function can be changed. --------------------------------*/ static double F(int x) { return (Math.pow(x,4)*Math.sin(x)-10*Math.pow(x,3)-20); } static void printFunctionValues() { System.out.println("\n\nFunction Values \n"); for (int i=0;i 1 ) { for (i=0;i