/*

g++ -o ga-example-002 -Wall -ansi -pedantic -std=c++11 -O3 ga-example-002.cc

./ga-example-002

 */

#include <iostream>
#include <fstream>

#include "ga.hpp"

// The width of the container is gaWIDTH. A set up consists of setting
// the position (barycenter) of some blocks in the container. It is a
// map: keys are the block number, and value is some position.

int main(int argc, char* argv[]) { 

  // This defines the blocks that we have to put in the
  // containers. This is a global parameter of our optimization
  // problem.
  ga::Blocks blocks;  

  blocks.clear();
  blocks.push_back(ga::Block(2,2)); // blocks[0]
  blocks.push_back(ga::Block(4,4)); // blocks[1]
  blocks.push_back(ga::Block(2,4)); // blocks[2]
  blocks.push_back(ga::Block(4,2)); // blocks[3]

  // This defines a specific arrangement of the previously defined
  // blocks in the container
  ga::Setup setup;

  double pos=0;

  // Here, we define a setup by adding blocks in the container at some
  // position. Each time a block is added, the drawing of the current
  // state of the container is displayed in the setup-01.fig file.
  
  std::ofstream file;
  xfig::open("setup-01.fig",file);

  setup[0] = ga::Position(1,1); // Set the position of block #0, i.e. blocks[0]
  xfig::draw(file,ga::Position(pos,0),
  	     blocks,setup);

  setup[3] = ga::Position(1.5,2); // Set the position of block #3
  xfig::draw(file,ga::Position(pos+=10,0),
  	     blocks,setup);

  setup[1] = ga::Position(2.5,3.5); // Set the position of block #1
  xfig::draw(file,ga::Position(pos+=10,0),
  	     blocks,setup);

  setup[2] = ga::Position(4,6);  // Set the position of block #2
  xfig::draw(file,ga::Position(pos+=10,0),
  	     blocks,setup);


  xfig::close(file);
  // Open the file with xfig.

  return 0;
}