Esempio n. 1
0
void addToGraphs(Graphs &graphs, OrderedSeq orderedSeq)
{
    bool added = false;
    for (int i = 0; i < graphs.size(); i++) {
        if (nestsIn(graphs[i].val, orderedSeq)) {
            addToGraphs(graphs[i].edges, orderedSeq);
            added = true;
        }
    }
    if (!added)
        graphs.push_back(Node(orderedSeq));
}
Esempio n. 2
0
int unmarshallGraph(const std::string& file, char delimiter) {
	Graphs graphs;
	graphs.unmarshall(file, delimiter);

	if(Env::verbose()) {
		std::cout << "Graphs: " << graphs.size() << std::endl;
		for (Graphs::Graph_map::iterator it = graphs.begin(); it != graphs.end(); it++) {
			std::cout << it->first << it->second << std::endl;
		}
	}

	std::shared_ptr<Graph> g = graphs.find("main");
	if (g == nullptr)
		return -9;

	if(Env::verbose()) {
		std::cout << "Name: " << g->name() << "Size: " << g->nodeCount() << std::endl;
	}
	std::shared_ptr<Node> n = g->start();
	printNode(n);

	g = graphs.find("Hello");
	if (g == nullptr)
		return -9;

	if(Env::verbose()) {
		std::cout << "Name: " << g->name() << "Size: " << g->nodeCount() << std::endl;
	}

	n = g->start();
	printNode(n);
	return 0;
}
Esempio n. 3
0
void printGraphs(const Graphs &graphs, int depth=0)
{
    for (int i = 0; i < graphs.size(); i++) {
        for (int j = 0; j < depth; j++)
            cout << "  ";
        printSequence(graphs[i].val);
        printGraphs(graphs[i].edges, depth + 1);
    }
}
Esempio n. 4
0
// this is totally f****d
vector<int> getLongestPath(const Graphs &graphs, vector<int> path=vector<int>())
{
    vector<int> longest(path); // lol so terrible
    int len = 0;
    for (int i = 0; i < graphs.size(); i++) {
        vector<int> dup(path);
        dup.push_back(graphs[i].val.second);
        vector<int> ret = getLongestPath(graphs[i].edges, dup);
        if (ret.size() > len) {
            longest = ret;
            len = ret.size();
        }
    }
    return longest;
}
int main(int argc, char **argv) {
    int diff, old_score, new_score;
    struct timeval start;
    gettimeofday(&start,NULL);
    Shapes s;
    s.readFile(argc, argv);
    s.buildConflictArray();
    Graphs g;
    g.buildConflictGraph(s.getShapes());
    s.findBoundingBox();
    Windows w;
    w.createWindow();
    w.countArea(s.getShapes(), g.getGraphs());
    g.countTotalColorDiff();

    Calculate c;
    //c.printResult(s.getShapes(), g.getGraphs(), w.getWindows(), argc, argv);
    //printf("real score : %.2f\n\n\n", c.real_score(w.getWindows()));

    //std::vector<Graph> &gg = g.getGraphs();
    //c.changeGraphColor(w.getWindows(), g.getGraphs()[0]);
    //c.changeGraphColor(w.getWindows(), g.getGraphs()[0]);
    //c.changeGraphColor(w.getWindows(), g.getGraphs()[2]);
    c.initial_total_color_diff(&g, g.getGraphs(), w.getWindows());
    //c.printResult(s.getShapes(), g.getGraphs(), w.getWindows(), argc, argv);
    //printf("real score : %.2f\n\n\n", c.real_score(w.getWindows()));

    for (int group_id = 0; group_id < c.group_size; group_id++) {
        c.iterative_sol(g.getGraphs(), w.getWindows(), group_id);
    }
    //printf("real score : %.2f\n\n\n", c.real_score(w.getWindows()));
    c.simulatedAnnealing(g.getGraphs(), w.getWindows(), start, argv[1]);

    for (int group_id = 0; group_id < c.group_size; group_id++) {
        c.iterative_sol(g.getGraphs(), w.getWindows(), group_id);
    }

    c.printResult(s.getShapes(), g.getGraphs(), w.getWindows(), argc, argv);
    printf("real score : %.2f\n\n\n", c.real_score(w.getWindows()));
    return 0;
}
Esempio n. 6
0
int main(int argc, char *argv[]) {

	try {
		Env::parseParams(argc, argv);


		if(Env::verbose()) {
			std::cout << std::endl;
			std::cout << "          __      _ __          " << std::endl;
			std::cout << "         / /___ _(_) / __    __ " << std::endl;
			std::cout << "    __  / / __ `/ / /_/ /___/ /_" << std::endl;
			std::cout << "   / /_/ / /_/ / / /_  __/_  __/" << std::endl;
			std::cout << "   \\____/\\__,_/_/_/ /_/   /_/   " << std::endl;
			std::cout << std::endl;
		}

		Env::initTimer();


		//Env::initIoDirectory();		// produces io folders from the callers location - not intended
		Env::showStatus();

		Graphs graphs;


		// ------------------------------------------------------------------------
		// FRONTEND
		// ------------------------------------------------------------------------

		if(Env::hasSrcFile()) {

			Env::printCaption("Frontend - Lexer");

			// Lexer
			Lexer lexer;
			lexer.lex(Env::getSrcFile());
			Env::showStatus();
			if(!lexer.hasFunctions()) {
				throw EnvException(FRONTEND_LEXER, "No rail functions found in " + Env::getSrcFile());
			}

			// Parser
			Env::printCaption("Frontend - Parser");
			Parser p(lexer.functions);
			graphs = p.parseGraphs(graphs);
			Env::showStatus();
		}
		else if(Env::hasSrcDeserialize()) {
			// Deserialize
			Env::printCaption("ASG - Deserialize");
			graphs.unmarshall(Env::getSrcDeserialize(), ';');
			Env::showStatus();
		}
		else {
			// handled within Env.h
		}

		// ------------------------------------------------------------------------
		// ASG
		// ------------------------------------------------------------------------

		// Serialize
		if(Env::hasDstSerialize()) {
			Env::printCaption("ASG - Serialize");
			graphs.marshall(Env::getDstSerialize(), ';');
		}
		Env::showStatus();

		// GraphViz
		if(Env::hasDstGraphviz()) {
			Env::printCaption("ASG - GraphViz");
			graphs.writeGraphViz(Env::getDstGraphviz());
		}
		Env::showStatus();




		// ------------------------------------------------------------------------
		// BACKEND
		// ------------------------------------------------------------------------
		if(Env::hasDstClassfile()) {
			Env::printCaption("Backend");

			// TODO #118
			ofstream outFile(Env::getDstClassfile(), std::ofstream::binary);
			Backend::Generate(graphs, &outFile);
			Env::showStatus();
			if(Env::verbose()) {
				std::cout << "done..." << std::endl;
			}
		}



		Env::printCaption("Finished");

		Env::printBuildStatus(!Env::hasErrors());
		return Env::hasErrors();

	}
	catch(EnvException &ee) {
		Env::showStatus();
		ee.showMessage();
		Env::printBuildStatus(false);
		return 1;
	}
	catch(...) {
		Env::addError(UNKNOWN, "An unhandled exception occurred");
		Env::showStatus();
		Env::printBuildStatus(false);
		return 1;
	}

}
Esempio n. 7
0
/** This method builds a minimum spanning tree 
 * for the given graph. This will be used to
 * calculate the total cost of the building
 * for the cheapest network.
 * */
Graphs* Graphs::minSpanTree()
{
  // reset all nodes to non visited
  int bIndex = 0;
  while (bIndex < vertexList.size())
  {
    vertexList[bIndex]->alreadyChecked = false; 
    bIndex++;
  }

   // create a new graph for spanning tree
   Graphs* spanGraph = new Graphs();


  // start spanning vertex
  Vertex* startVert = vertexList[0];

  // set pointer and boolean value
  startVert->prevPtr = NULL;
  startVert->alreadyChecked = true;


  // create a pqueue to hold edge, edge vector and cost compare class
  priority_queue<Edges, vector<Edges>, CompareEdgeCost> mySpanQueue;

  // enqueue to the priority queue
  int index = 0;
  while(index < startVert->ListEdgesAround.size())
  {
    mySpanQueue.push(startVert->ListEdgesAround[index]);
    index++;
  }


  // dequeue from pqueue
  while(mySpanQueue.empty() != true)
  {
    // save the top of the queue
    Edges edg = mySpanQueue.top();
    
    // dequeue shortest edge from the queue
    mySpanQueue.pop();

    // if end vert is visited then continue
    if( edg.endVert->alreadyChecked)
      continue;
      
    // set end vertex to visited 
    edg.endVert->alreadyChecked = true;

    // set prev of w to indicate v
    edg.endVert->prevPtr = edg.initVert;

    // create 2 vertices to make the edge for MST
    Vertex* initSpanVert = new Vertex(edg.initVert->stringName);
    Vertex* endSpanVert = new Vertex(edg.endVert->stringName);

    // set the ptr to existing vertex
    if ((spanGraph->containsVertex(initSpanVert->stringName))) 
      initSpanVert = spanGraph->getVertex(initSpanVert->stringName);
    
    // if vertex not on the graph, then add new one
    else 
      spanGraph->vertexList.push_back(initSpanVert);
    
    // else set ptr to existing vertex
    if ((spanGraph->containsVertex(endSpanVert->stringName))) 
      endSpanVert = spanGraph->getVertex(endSpanVert->stringName);

    // if vertex not on graph, then add new one
    else 
      spanGraph->vertexList.push_back(endSpanVert);
    
    // add the vertices
    initSpanVert->createEdge( endSpanVert, edg.edgeCost, edg.transmitTime);
    endSpanVert->createEdge( initSpanVert, edg.edgeCost, edg.transmitTime);

    // create w's adjacency list
    vector<Edges> wAdjList = edg.endVert->ListEdgesAround;

    // push each edge of w's adjacent list to queue
    int wIndex = 0;
    while (wIndex < wAdjList.size()){
      mySpanQueue.push(wAdjList[wIndex]);
      wIndex++;
    }
    
  }

  // return the minimum spanning tree
  return spanGraph;


}