コード例 #1
0
ファイル: DataCloud.cpp プロジェクト: richard-liang/DataCloud
int main() {
//	srand(time(NULL));
	Environment env;
	Point *point = new Point();
	ofstream pointFile("point.txt");
	ofstream linkFile("link.txt");
	ifstream inFile("timelist.txt");
	queue<tuple<int, int, int>> data;
	int id1, id2, times;
	while (!inFile.eof()) {
		string line;
		getline(inFile, line);
		sscanf_s(line.c_str(), "%d %d %d", &id1, &id2, &times);
		tuple<int, int, int> tu(id1, id2, times);
		data.push(tu);
	}
	cout << data.size() << endl;
	point->id = 1;
	for (int i = 0; i < 3; i++) {
		point->pos[i] = 0.0;
	}
	env.init(point);
	bool allPointAdded = false;
	int step = 0;
	for ( step = 0; step < 30000; step++) {
		env.update();
		//		Sleep(100);
		if (step % 1000 == 0) {
			cout << "energy: " << env.getEnergy() << endl;
			cout << step << ' ' << env.timePassed << ' ' << env.timeSlice << endl;
		}
		while (!data.empty() && get<2>(data.front()) <= env.timePassed / TIMESLICE) {
			id1 = get<0>(data.front());
			id2 = get<1>(data.front());
			env.addPoint(id1, "", id2, "");
			data.pop();
		}
		if (data.empty()) {
			// if all points were added
			break;
		}
		if (step % 100 == 0) {
			pointFile << step / 100 << '\n';
			for (Point *p : env.points) {
				pointFile << p->pos[0] << '\t' << p->pos[1] << '\t' << p->pos[2] << '\t' << p->radius << '\n';
			}
			linkFile << step / 100 << '\n';
			for (Link *l : env.links) {
				linkFile << l->first->pos[0] << '\t' << l->first->pos[1] << '\t' << l->first->pos[2] << '\t';
				linkFile << l->second->pos[0] << '\t' << l->second->pos[1] << '\t' << l->second->pos[2] << '\n';
			}
		}
	}
	cout << "perpare skeleton env" << endl;
	// treat a group of points as one point
	Environment *skeletonEnv = env.getSkeleton();
	cout << "Skeleton Enviroment!!" << endl;
	cout << skeletonEnv->points.size() << " points " << skeletonEnv->links.size() << " links" << endl;
	for (; step < 30000; step++) {
		skeletonEnv->update();
		if (step % 1000 == 0) {
			cout << "enerty: " << skeletonEnv->getEnergy() << endl;
			cout << step << ' ' << skeletonEnv->timePassed << ' ' << skeletonEnv->timeSlice << endl;
		}
		if (step % 100 == 0) {
			pointFile << step / 100 << '\n';
			for (Point *p : skeletonEnv->points) {
				pointFile << p->pos[0] << '\t' << p->pos[1] << '\t' << p->pos[2] << '\t' << p->radius << '\n';
			}
			linkFile << step / 100 << '\n';
			for (Link *l : skeletonEnv->links) {
				linkFile << l->first->pos[0] << '\t' << l->first->pos[1] << '\t' << l->first->pos[2] << '\t';
				linkFile << l->second->pos[0] << '\t' << l->second->pos[1] << '\t' << l->second->pos[2] << '\n';
			}
		}
	}
	pointFile.close();
	return 0;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: Bk8/BeamTracing
void buildEnvironment()
{
    /*
    *----*----*--------*
    |    |    |        |
    |  A .    |   D    |
    |    |    |        |
    *----*  C |        |
    |    |    *---   --*
|  B .   .             |
    |    |    .   E    |
    *----*-------------*
    */
    
    // Points
    env.addPoint(core::Pointf(0, 0));     // 0
    env.addPoint(core::Pointf(0, 10));    // 1
    env.addPoint(core::Pointf(10, 10));   // 2
    env.addPoint(core::Pointf(10, 0));    // 3
    env.addPoint(core::Pointf(5, 0));     // 4
    env.addPoint(core::Pointf(10, -10));  // 5
    env.addPoint(core::Pointf(0, -10));   // 6
    env.addPoint(core::Pointf(-5, -10));  // 7
    env.addPoint(core::Pointf(-5, -7));   // 8
    env.addPoint(core::Pointf(-10, -10)); // 9
    env.addPoint(core::Pointf(-10, 0));   // 10
    env.addPoint(core::Pointf(-5, 0));    // 11
    env.addPoint(core::Pointf(-5, -3));   // 12
    env.addPoint(core::Pointf(-5, 3));    // 13
    env.addPoint(core::Pointf(-10, 10));  // 14
    env.addPoint(core::Pointf(-5, 10));   // 15
    env.addPoint(core::Pointf(-5, 7));    // 16
    env.addPoint(core::Pointf(3, 0));     // 17
    
    // Walls
    env.addWall(Wall (14, 10, 0.0));       // 0    
    env.addWall(Wall (15, 14, 0.0));       // 1    
    env.addWall(Wall (1, 15, 0.0));        // 2    
    env.addWall(Wall (2, 1, 0.0));         // 3    
    env.addWall(Wall (3, 2, 0.0));         // 4    
    env.addWall(Wall (5, 3, 0.0));         // 5    
    env.addWall(Wall (6, 5, 0.0));         // 6    
    env.addWall(Wall (7, 6, 0.0));         // 7    
    env.addWall(Wall (9, 7, 0.0));         // 8    
    env.addWall(Wall (10, 9, 0.0));        // 9    
    env.addWall(Wall (10, 11, 0.0));       // 10    
    env.addWall(Wall (15, 16, 0.0));       // 11
    env.addWall(Wall (13, 11, 0.0));       // 12
    env.addWall(Wall (11, 12, 0.0));       // 13
    env.addWall(Wall (8, 7, 0.0));         // 14
    env.addWall(Wall (0, 1, 0.0));         // 15
    env.addWall(Wall (17, 0, 0.0));        // 16
    env.addWall(Wall (3, 4, 0.0));         // 17
    env.addWall(Wall (8, 12, INFINITY));  // 18
    env.addWall(Wall (0, 6, INFINITY));   // 19
    env.addWall(Wall (17, 4, INFINITY));  // 20
    env.addWall(Wall (16, 13, INFINITY)); // 21
    
    // Rooms
    Room rA, rB, rC, rD, rE;
    rA.setIdx(0);
    rB.setIdx(1);
    rC.setIdx(2);
    rD.setIdx(3);
    rE.setIdx(4);
    
    // Room A
    rA.addWall(0,   1);
    rA.addWall(1,   1);
    rA.addWall(11, -1);
    rA.addWall(21, -1);
    rA.addWall(12, -1);
    rA.addWall(10,  1);
    
    env.addRoom(rA);
    
    // Room B
    rB.addWall(8,   1);
    rB.addWall(14, -1);
    rB.addWall(18,  1);
    rB.addWall(13, -1);
    rB.addWall(10, -1);
    rB.addWall(9,   1);
    
    env.addRoom(rB);

    // Room C
    rC.addWall(2,   1);
    rC.addWall(11,  1);
    rC.addWall(21,  1);
    rC.addWall(12,  1);
    rC.addWall(13,  1);
    rC.addWall(18, -1);
    rC.addWall(14,  1);
    rC.addWall(7,   1);
    rC.addWall(19, -1);
    rC.addWall(15,  1);
    
    env.addRoom(rC);

    // Room D
    rD.addWall(3,   1);
    rD.addWall(20,  1);
    rD.addWall(16, -1);
    rD.addWall(15, -1);
    rD.addWall(17, -1);
    rD.addWall(4,   1);
    
    env.addRoom(rD);
    
    // Room E
    rE.addWall(17, 1);
    rE.addWall(20, -1);
    rE.addWall(16,  1);
    rE.addWall(19,  1);
    rE.addWall(6,   1);
    rE.addWall(5,   1);
    
    env.addRoom(rE);
    
    Source src(rD, core::Pointf(5, 5));
    env.setSource(src);
    
    std::vector<std::vector<Environment::GraphNode> > adj;
    adj.resize(env.getRooms().size());
    env.buildAdjacencyGraph(adj);
    
    env.DFS(adj, src.getInsideRoom().getRoomIdx());
    
    env.filterValidPaths(2);
    env.getValidPaths()->getNumberOfLeaves(env.getValidPaths()->_root, numberOfPaths);
    env.getValidPaths()->getDepth(env.getValidPaths()->_root, maximumDepth, 0);
    
    std::cout << numberOfPaths << " valid paths found" << std::endl;
    std::cout << "Depth: " << maximumDepth << std::endl;
}