/* 
 * File:   Placer.h
 * Author: macino
 *
 * Created on Nedea, 2008, december 14, 16:41
 */

#ifndef _PLACER_H
#define	_PLACER_H

#include <queue>
#include <vector>

#include "Circuit.h"
#include "Rule.h"
#include "Piece.h"

//umiestnovac prvkov a ich spojov
class Placer {
	//odkaz na reprezentaciu obvodu
    Circuit* circuit;
	//fronta spracovavanych pravidiel
    queue<Rule*> *processQueue;
	//fronta pravidiel cakajucich na dodatocne spracovanie
    queue<Rule*> *waitQueue;
	//mapa vertikalnych vrstiev prvkov
	vector<vector<Piece*>*> *mapLayers;
	//hustota vertikalnych vrstiev
	vector<int> *densityMap;
	//optimalna pozicia pre kazdt prvok vo vrstve
	vector<int> *yoptm;
	int wireNum;

	//prvotne umiestnenie prvkov
    void primalPlace();
    bool connect(Rule* rule);
    void place(Rule* rule);
    void placeWire(Rule* rule);
    void horizontalPieceOptm();
    void mapLayerHoriz();
    void mapDensity();
    bool moveCandidate(int levelFrom);
	void verticalPieceOptm();
	void calculateYOptm(Piece* p);
	void moveToYOptm(Piece* p, vector<Piece*>* map);
	void createNodes();
	void route();
	void routeConnection(Node *nStart, Node *nEnd);
	double f(vector<Point> *path, Node *nEnd);
	void mergePoints(Connection *c);

public:
    Placer(Circuit* circuit);
    ~Placer();
    Circuit* getCircuit();
    void placeCircuit();
};

#endif	/* _PLACER_H */

