Monte Carlo Optimization Algorithm

edited June 2014 in General Discussion

Hi All, I'm searching for any example that use Monte Carlo optimization method, any link? Thanks for the info

Best David

Answers

  • I suppose the request was in the context of Processing, but nearly any generic algorithm, and Java examples, can be adapted to Processing.

  • edited June 2014

    it's a very broad question

    one of the easiest might be to calculate PI

    http://en.wikipedia.org/wiki/Monte_Carlo_method#Simulation_and_optimization

  • Thanks for the answers. I'm just searching for code that implements monteCarlo in an example of how to find the optimal path for nodes that search for a goal, and there are different sort of goals with different weights.

  • Answer ✓

    You might consider ant colony optimal path strategy. See:

    http://en.wikipedia.org/wiki/Ant_colony_optimization_algorithms

  • edited June 2014

    true! I read about it too. Maybe I should open other discussion for (ACO). Here a little example of Monte Carlo PI. But far away of what I'm searching here in the forum:

    // Monte Carlo 
    // David Dalmazzo
    // 20/06/2014
    
    int counter = 100;
    
    void setup() {
      size(800, 800);
    }
    
    
    void draw() {
      background(50);
      println(getPi(counter));
      counter *= 10;
    }
    
    float getPi(int n) {
      int inCircle = 0;
    
      for (int i = 0; i < n; i++) {
        float randX = random(0, 2) -1;
        float randY = random(0, 2) -1;
        stroke(255);
        point((randX+1) * width, (randY+1) * width); 
        float distance = sqrt(randX * randX + randY * randY);
        if (distance < 1) {
          inCircle++;
          stroke(0, 0, 255);
          point((randX+1) * width, (randY+1) * width);
        }
      }
      return 4.0 * inCircle / n;
    }
    
  • Hey Jas, Have you seen any example in processing that use something like ant colony optimal path strategy? Maybe in Nature Of Code

Sign In or Register to comment.