QVariant RecentFileModel::data(int index, int role) const
{
    if (role == NameRole)
        return displayPath(m_paths.at(index));
    if (role == FileNameRole)
        return m_paths.at(index);
    return QVariant();
}
QHash<int, QVariant> RecentFileModel::data(int index, const QList<int> &/*roles*/) const
{
    QHash<int,QVariant> dataHash;

    dataHash.insert(NameRole, displayPath(m_paths.at(index)));
    dataHash.insert(FileNameRole, m_paths.at(index));
    return dataHash;
}
int main()
{
    Node *root = makeBST();
    displayPath(root,25);
    cout << endl;
    displayPath1(root,25);


    return 0;
}
Beispiel #4
0
/////////////////////////////////////////
// Path Debugging
/////////////
void pathPlan::togglePathReset()
{
	displayPath(true);
	displayBuildPath(false);
	displayDebug(false);
	if(m_CS) delete m_CS;
	m_CS = 0;
	hitPoints.clear();
	contactPoints.clear();
}
void displayPath(Node *root,int key)
{
    if(root)
    {
        if(key == root->data)
        {
            cout << root->data << ",";
        }
        else if(key < root->data)
        {
            cout << root->data << ",";
            displayPath(root->left,key);
        }
        else
        {
            cout << root->data << ",";
            displayPath(root->right,key);
        }
        
    }
}
Beispiel #6
0
void PathCollector::displayAllPaths() {
	std::cout << "**********\n DISPLAYING PATHS ***********\n" << std::endl;
	std::cout << "pathSet.size() " << pathSet.size() << std::endl;
	std::vector<std::vector<SgGraphNode*> >::iterator i = pathSet.begin();
	int pathnum = 1;
	for(;i!=pathSet.end();i++) {
		std::cout << "path " << pathnum << std::endl;
		displayPath(*i);
		pathnum++;
	}
	std::cout << "\n******** PATHS DISPLAYED **********\n" << std::endl;
	return;
}
Beispiel #7
0
void pathPlan::goForGoal(btVector3 start, btVector3 end)
{
	memset(&m_startPoint,0,sizeof(rankPoint));
	m_startPoint.point = start;
	memset(&m_goalPoint,0,sizeof(rankPoint));
	m_goalPoint.point = end;
	
	m_state = PS_SEARCHING;
	m_straightDistance = start.distance(end);
	m_progressLimit = m_straightDistance / m_efficiencyLimit;
	m_spinDirection = 0;
	
	displayCurrentSearch(true);								// turn on drawing the yellow search lines
	displayBuildPath(true);
	
	if(m_view) m_view->overlayString(QString("Searching Range %1").arg(m_range));
	
	m_time.start();											// start time of path calculation
	
	if(m_range == 0) {
		m_state = this->AStarSearch();						// if infinite range find the shortest path
	}
	else {
		m_state = this->cycleToGoal();						// step forward on path until the goal is in range

		m_GP.points = m_trailPath + m_GP.points;			// prepend the step trail point list
		m_trailPath.clear();
		m_GP.length = 0;
		for(int i=0; i<m_GP.points.size()-1; i++) 
			m_GP.length += m_GP.points[i].point.distance(m_GP.points[i+1].point);	// calculate the total length
		m_startPoint = m_GP.points[0];						// set the starting point for drawing
	}
	
	if(m_goalOccluded && m_state == PS_COMPLETE) 			// path is complete but the goal is occluded
		m_state = PS_GOALOCCLUDED;							// set the state
	
	m_GP.time = m_time.elapsed();							// get the elapsed time for the path generation
	
	if(m_CS) delete m_CS;									// delete the C Space to free up memory since it is not needed
	m_CS = 0;
	m_pointPath.clear();									// clear out the construction point path
	
	displayCurrentSearch(false);							// turn off search path drawing
	displayBuildPath(false);
	displayPath(true);
			
	if(m_GP.length != 0) m_GP.efficiency = m_straightDistance/m_GP.length;
}
Beispiel #8
0
void GotoFileList::OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const {
	const bool isCurrent = IsCurrent(n);

	if (isCurrent) dc.SetTextForeground(m_hlTextColor);
	else dc.SetTextForeground(m_textColor);

	const FileEntry& file_entry = *m_items[n].file_entry;

	// m_project_root
	wxFileName displayPath(file_entry.path);
	displayPath.MakeRelativeTo(this->m_project_root);
	//displayPath.SetFullName(file_entry.name);

	const wxString& name = displayPath.GetFullPath();

	const int path_size = displayPath.GetPath().size() + 1;

	const std::vector<unsigned int>& hl = m_items[n].hlChars;
	std::vector<unsigned int> offsets(hl.size());
	for(unsigned int i = 0; i < hl.size(); i++) {
		offsets[i] = hl[i] + path_size;
	}

	/*// Calc extension width
	static const wxString ext = wxT("..  ");
	dc.SetFont(m_font);
	int w, h;
	dc.GetTextExtent(ext, &w, &h);
	const unsigned int extwidth = w;

	// See if we have to resize the action name to fit
	// note that this is not 100% correct as bold chars take up a bit more space.
	unsigned int len = name.length();
	dc.GetTextExtent(name, &w, &h);
	if (w > (int)rightBorder) {
		do {
			name.resize(--len);
			dc.GetTextExtent(name, &w, &h);
		} while (len > 0 && w + extwidth > (int)rightBorder);
		name += ext;
	}*/

	// Draw action name
	DrawItemText(dc, rect, name, offsets, isCurrent);
}
Beispiel #9
0
//path finding algorithm based on Lee's algorithm
void findPath ()
{
	//Init
	entryNode->label = 0;

	//Wave expansion
	print(1, 1, "Pathfinder initialized, starting wave expansion...\n");
	startStopwatch ();
	expand (&entryNode, 1); //use wave expansion
	expansionTime = stopStopwatch ();
	displayGrid (); //print results

	//Backtrace
	print(1, 1, "Tracing back path...\n\n");
	startStopwatch ();
	backTrace ();
	backTraceTime = stopStopwatch ();
	displayPath (); //print results

}
Beispiel #10
0
pathPlan::pathPlan(obstacles *obs,simGLView* glView)
:
simGLObject(glView),
m_blocks(obs),
m_CS(NULL),
m_range(0),
m_margin(SPACEMARGIN),
m_step(0.25),
m_visibilityType(false),
m_goalOccluded(NULL),
m_efficiencyLimit(0.3),
m_spinProgress(6),
m_spinProgressBase(0),
m_state(PS_SEARCHING),
m_drawSwitch(true),
m_linkViewIndex(0)
{
	// create callbacks to all the drawing methods, these are added to/removed from the display list
	// make sure these remain in order to match with the enumeration
	ACallback<pathPlan> drawCB(this, &pathPlan::drawDebugPath);	m_drawingList << drawCB;
	drawCB.SetCallback(this,&pathPlan::drawCrowFlyLine); 		m_drawingList << drawCB;
	drawCB.SetCallback(this,&pathPlan::drawCurrentSearchPath);	m_drawingList << drawCB;
	drawCB.SetCallback(this,&pathPlan::drawRangeFan);			m_drawingList << drawCB;
	drawCB.SetCallback(this,&pathPlan::drawPathBaseLine);		m_drawingList << drawCB;
	drawCB.SetCallback(this,&pathPlan::drawLightTrail);			m_drawingList << drawCB;
	drawCB.SetCallback(this,&pathPlan::drawPathBuildLine);		m_drawingList << drawCB;
	
	m_GP.length = 0;
	m_GP.time = 0;
	m_GP.efficiency = 0;
	
	displayBuildPath(false);
	displayPath(false);
	displayLightTrail(false);
	displayCrowFly(false);
	displayDebug(false);
	displayCspace(false);
}
Beispiel #11
0
bool GreedyBestFirst::DoSearch(Tree::Node* currNode)
{
	if (currNode == NULL)
		currNode = m_searchTree->getHead();

	m_path.push_back(currNode->vert);
	currNode->path = m_path;

	// Add to closed list
	m_closedList.insert(make_pair(currNode->vert, currNode));

	// Return true if dest has been reached
	if (currNode->vert == m_end)
		return true;

	// fetch edges connected to current vertex
	list<Graph::Edge*> conns = m_searchSpace->getConnectedEdges(currNode->vert);

	// create a node for each connection if one of following is true:
	//	- The vertex has not been visited
	for (list<Graph::Edge*>::iterator itr = conns.begin(); itr != conns.end(); ++itr)
	{
		// Compute cost of this path
		int nextCost = currNode->cost + (*itr)->cost;

		Graph::Vertex* endVert;
		if ((*itr)->ends[0] == currNode->vert)
			endVert = (*itr)->ends[1];
		else
			endVert = (*itr)->ends[0];

		// Figure out which end is the start, add child accordingly if not already visited
		if (!endVert->visited)
			m_searchTree->addAsChild(nextCost, endVert, currNode, &m_path);
	}

	// fetch children of current node
	list<Tree::Node*> currChildren = currNode->getChildren();

	// if no children and not at dest, not on correct path
	if (currChildren.empty())
	{
		return false;
	}

	// append to open list
	m_openList.insert(m_openList.end(), currChildren.begin(), currChildren.end());
	sort(m_openList.begin(), m_openList.end(), CompareFunc);
	if( m_verbose )
		displayOpenList();

	// mark current vertex visited
	currNode->vert->visited = true;

	Tree::Node* nextNode;
	// get first entry in open list and remove from open list
	do
	{
		if (m_openList.empty())
			return false;
		nextNode = *m_openList.begin();
		m_openList.pop_front();
	}
	while( nextNode->vert->visited );

	// set path to next node's path
	m_path = nextNode->path;

	if (m_verbose)
	{
		displayPath(currNode);
		cout << "Expanding node " << nextNode->vert->id << endl;
	}

	if (DoSearch(nextNode))
		return true;
	

	// default case, no path found
	m_path.clear();
	return false;
}
void display(void)
{

   GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
   GLfloat sun_ambient[] = { 1.0, 1.0, 0.0, 1.0 };
   GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 };
   GLfloat sun_diffuse[] = { 0.6, 0.6, 0.0, 1.0 };
   GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat no_shininess[] = { 0.0 };
   GLfloat low_shininess[] = { 5.0 };
   GLfloat sun_shininess[] = { 70.0 };
   GLfloat sun_emission[] = {0.3, 0.3, 0.0, 0.0};

	GLfloat mercury_ambient[] = { 0.6, 0.1, 0.0, 1.0 };
	GLfloat mercury_diffuse[] = { 0.6, 0.1, 0.0, 1.0 };
	GLfloat mercury_shininess[] = { 30.0 };
    GLfloat mercury_emission[] = {0.2, 0.2, 0.0, 0.0};

	GLfloat venus_ambient[] = { 0.6, 0.3, 0.0, 1.0 };
	GLfloat venus_diffuse[] = { 0.6, 0.3, 0.0, 1.0 };
	GLfloat venus_shininess[] = { 30.0 };
    GLfloat venus_emission[] = {0.2, 0.3, 0.0, 0.0};

	GLfloat earth_ambient[] = { 0.2, 0.2, 0.55, 1.0 };
	GLfloat earth_diffuse[] = { 0.2, 0.2, 0.55, 1.0 };
	GLfloat earth_shininess[] = { 40.0 };
    GLfloat earth_emission[] = {0.1, 0.1, 0.45, 0.0};

	GLfloat mars_ambient[] = { 0.75, 0.2, 0.02, 1.0 };
	GLfloat mars_diffuse[] = { 0.75, 0.2, 0.02, 1.0 };
	GLfloat mars_shininess[] = { 30.0 };
    GLfloat mars_emission[] = {0.3, 0.2, 0.0, 0.0};

	GLfloat jupitor_ambient[] = { 0.9, 0.7, 0.3, 1.0 };
	GLfloat jupitor_diffuse[] = { 0.9, 0.7, 0.3, 1.0 };
	GLfloat jupitor_shininess[] = { 20.0 };
	GLfloat jupitor_emission[] = {0.1, 0.1, 0.0, 0.0};

	GLfloat saturn_ambient[] = { 0.6, 0.6, 0.4, 1.0 };
	GLfloat saturn_diffuse[] = { 0.6, 0.6, 0.4, 1.0 };
	GLfloat saturn_shininess[] = { 20.0 };
	GLfloat saturn_emission[] = {0.2, 0.2, 0.0, 0.0};

	GLfloat uranus_ambient[] = { 0.4, 0.6, 0.8, 1.0 };
	GLfloat uranus_diffuse[] = { 0.4, 0.6, 0.8, 1.0 };
	GLfloat uranus_shininess[] = { 20.0 };
	GLfloat uranus_emission[] = {0.1, 0.2, 0.5, 0.0};

	GLfloat neptune_ambient[] = { 0.4, 0.0, 0.6, 1.0 };
	GLfloat neptune_diffuse[] = { 0.4, 0.0, 0.6, 1.0 };
	GLfloat neptune_shininess[] = { 20.0 };
	GLfloat neptune_emission[] = {0.1, 0.1, 0.2, 0.0};

	GLfloat pluto_ambient[] = { 0.4, 0.1, 0.7, 1.0 };
	GLfloat pluto_diffuse[] = { 0.4, 0.1, 0.7, 1.0 };
	GLfloat pluto_shininess[] = { 20.0 };
	GLfloat pluto_emission[] = {0.0, 0.2, 0.3, 0.0};

	
	if (deltaMove)
		computePos(deltaMove);
	if (deltaAngle)
		computeDir(deltaAngle);

 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   glColor3f (1.0, 1.0, 1.0);

   //glRotatef(5.0,1.0,0.0,0.0);

   glPushMatrix();
    gluLookAt(	x, 1.0f, z,
				x+lx, 1.0f,  z+lz,
				0.0f, 1.0f,  0.0f);

 	glRotatef(rotateScene,1.0,0.0,0.0);
	if(flag==1)
	displayPath();
	

	glPushMatrix();
		glMaterialfv(GL_FRONT, GL_AMBIENT, sun_ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, sun_diffuse);
		//glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, sun_shininess);
		glMaterialfv(GL_FRONT, GL_EMISSION, sun_emission);
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		gluSphere(sun,1.5,20,20);
		//glutSolidSphere(1.5, 20, 20);   /* draw sun */
	glPopMatrix();

	glPushMatrix();
		glRotatef ((GLfloat) mercuryRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, mercury_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, mercury_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS, mercury_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, mercury_emission);
			glTranslatef (2.0, 0.0, 0.0);
			 glBindTexture(GL_TEXTURE_2D, texture[1]);
			 gluSphere(mercury,.2,20,18);
		glPopMatrix();
		if(mercuryRot>=360.0)
			mercuryRot=0.0;
	mercuryRot=mercuryRot+1.0 ;
	glPopMatrix();

	glPushMatrix();
		glRotatef ((GLfloat) venusRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, venus_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, venus_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS, venus_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, venus_emission);
			glTranslatef (4.0, 0.0, 0.0);
			 glBindTexture(GL_TEXTURE_2D, texture[2]);
			 gluSphere(venus,.4,20,18);
		glPopMatrix();
			venusRot=venusRot+.800;
			if(venusRot>=360.0)
			venusRot=0.0;
	glPopMatrix();

	glPushMatrix();
		glRotatef(rotateAstroid,0.0,1.0,0.0);
		makeAstroidBelt();
		rotateAstroid+=0.3;
	glPopMatrix();


	glPushMatrix();
		glRotatef ((GLfloat) earthRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, earth_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, earth_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,earth_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, earth_emission);
			glTranslatef (6.0, 0.0, 0.0);
			glBindTexture(GL_TEXTURE_2D, texture[3]); //earth
			 gluSphere(earth,.5,20,18);
			earthRot=earthRot+.5;
			if(earthRot>=360.0)
			earthRot=0.0;
		glPopMatrix();
	glPopMatrix();

	glPushMatrix();
		glRotatef ((GLfloat) marsRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, mars_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, mars_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,mars_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, mars_emission);
			glTranslatef (8.0, 0.0, 0.0);
			//glutSolidSphere(0.65, 20, 18); //mars
			glBindTexture(GL_TEXTURE_2D, texture[4]);
			 gluSphere(mars,.65,20,18);
			marsRot=marsRot+0.53;
				if(marsRot>=360.0)
			marsRot=0.0;
		glPopMatrix();		
	glPopMatrix();



	glPushMatrix();
		glRotatef ((GLfloat) jupitorRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
		glRotatef (90.0,1.0,0.0,0.0);
			glMaterialfv(GL_FRONT, GL_AMBIENT, jupitor_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, jupitor_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,jupitor_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, jupitor_emission);
			glTranslatef (10.0, 0.0, 0.0);
			//glutSolidSphere(0.8, 20, 18);  //jupiter
			glBindTexture(GL_TEXTURE_2D, texture[5]);
			 gluSphere(jupiter,.9,20,18);
			jupitorRot=jupitorRot+0.084;
				if(jupitorRot>=360.0)
			jupitorRot=0.0;
		glPopMatrix();
	glPopMatrix();

	glPushMatrix();
		glRotatef ((GLfloat) saturnRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, saturn_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, saturn_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,saturn_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, saturn_emission);
			glTranslatef (12.0, 0.0, 0.0);
			circle(0.0,0.0,0.0,0.9);
			circle(0.0,0.0,0.0,0.85);
			circle(0.0,0.0,0.0,0.95);
			circle(0.0,0.0,0.0,1.0);
			circle(0.0,0.0,0.0,1.05);
			circle(0.0,0.0,0.0,1.10);
			circle(0.0,0.0,0.0,1.15);
			//glutSolidSphere(0.7, 20, 18);  //saturn
			glBindTexture(GL_TEXTURE_2D, texture[6]);
			gluSphere(saturn,.7,20,18);
			saturnRot=	saturnRot+	0.034;
			if(saturnRot>=360.0)
			saturnRot=0.0;
		glPopMatrix();
	glPopMatrix();

	glPushMatrix();
		glRotatef ((GLfloat) uranusRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, uranus_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, uranus_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,uranus_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, uranus_emission);
			glTranslatef (14.0, 0.0, 0.0);
			glBindTexture(GL_TEXTURE_2D, texture[7]);
			gluSphere(uranus,.6,20,18);
			uranusRot=uranusRot+0.012;
				if(uranusRot>=360.0)
			uranusRot=0.0;
		glPopMatrix();		
	glPopMatrix();
	
	glPushMatrix();
		glRotatef ((GLfloat) neptuneRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, neptune_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, neptune_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,neptune_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, neptune_emission);
			glTranslatef (16.0, 0.0, 0.0);
		//	glutSolidSphere(0.3, 20, 18); //neptune
			glBindTexture(GL_TEXTURE_2D, texture[8]);
			gluSphere(neptune,.3,20,18);
			neptuneRot=neptuneRot+0.007;
				if(neptuneRot>=360.0)
			neptuneRot=0.0;
		glPopMatrix();
	glPopMatrix();

	glPushMatrix();
		glRotatef ((GLfloat) plutoRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, pluto_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, pluto_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,pluto_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, pluto_emission);
			glTranslatef (18.0, 0.0, 0.0);
			//glutSolidSphere(0.3, 20, 18);  //pluto
			glBindTexture(GL_TEXTURE_2D, texture[9]);
			gluSphere(pluto,.3,20,18);
			plutoRot=plutoRot+0.004;
				if(plutoRot>=360.0)
			plutoRot=0.0;
		glPopMatrix();
	glPopMatrix();
	
   glFlush();
   glPopMatrix();
   skyBox();
   glutSwapBuffers();
}
Beispiel #13
0
int
main(int argc, char *argv[]){
	graph_t graph;
	int i, j, k, dijk=0;
	char ch, str[6];
	if(argc!=2){
		printf("Usage: %s <input filename>\n", argv[0]);
		exit(1);
	}
	FILE *fp = fopen(argv[1], "r");
	if(fp==NULL){
		printf("File not found.\n");
		exit(1);
	}
	
	graph.numOfVertices=0;
	//Checking the number of vertices
	while((ch=fgetc(fp))!='\n'){
		if(ch==' ')
			graph.numOfVertices++;
	}
	graph.numOfVertices=graph.numOfVertices+1;

	//Reading from the text file
	i=1, j=1;
	rewind(fp);
	while(!feof(fp)){
		ch = fgetc(fp);
		if(ch!=' ' && ch!='\n'){
			str[k]=ch;
			k++;
		}else{
			if(str[0]!='x'){
				graph.dist[i][j]=atoi(str);
			}else{
				graph.dist[i][j]=INFINITY;
			}
			for(k=0; str[k]!='\0'; k++){
				str[k]='\0';
			}
			k=0;
			if(ch==' '){
				j++;
			}else if(ch=='\n'){
				i++;
				j=1;
			}
		}
	}
	fclose(fp);

	//Initializations
	for(i=1; i<=graph.numOfVertices; i++){
		for(j=1; j<=graph.numOfVertices; j++){
			if(j==i || graph.dist[i][j]==INFINITY){
				graph.pred[i][j]=0;
			}else{
				graph.pred[i][j]=i;
			}
		}
	}
	
	//Floyd's Algorithm
	for(k=1; k<=graph.numOfVertices; k++){
		for(i=1; i<=graph.numOfVertices; i++){
			for(j=1; j<=graph.numOfVertices; j++){
				dijk = graph.dist[i][k] + graph.dist[k][j];
				if(dijk < graph.dist[i][j]){
					graph.dist[i][j] = dijk;
					graph.pred[i][j] = graph.pred[k][j];
				}
			}
		}
	}
		
	//Display path
	for(i=1; i<=graph.numOfVertices; i++){
		for(j=1; j<=graph.numOfVertices; j++){
			if(i!=j)
				displayPath(&graph, i, j);
		}
	}

	return 0;
}
//旅客选择更改,显示更改
void Widget::travelerChanged()
{
    ui->StartButton->setEnabled(true);
    //当前旅客执行过构造计划,则将界面显示为该旅客的信息
    if (startclicked[ui->TravelerComboBox->currentIndex()])
    {
        qDebug() << "Change traveler to who possesses a plan, display his/her info and plan";
        ui->StartDateTimeEdit->setDateTime(travelers[ui->TravelerComboBox->currentIndex()].startTime);
        int deaDay = travelers[ui->TravelerComboBox->currentIndex()].deadlineTime.date().day();
        QDateTime deadlineDateTime;
        deadlineDateTime.setDate(QDate(travelers[ui->TravelerComboBox->currentIndex()].deadlineTime.date().year(), travelers[ui->TravelerComboBox->currentIndex()].deadlineTime.date().month(), deaDay));
        deadlineDateTime.setTime(QTime(travelers[ui->TravelerComboBox->currentIndex()].deadlineTime.time()));
        ui->DeadlineDateTimeEdit->setDateTime(deadlineDateTime);
        ui->StrategyComboBox->setCurrentIndex(travelers[ui->TravelerComboBox->currentIndex()].strategy);
        ui->StartComboBox->setCurrentIndex(travelers[ui->TravelerComboBox->currentIndex()].origin);
        ui->DestinationComboBox->setCurrentIndex(travelers[ui->TravelerComboBox->currentIndex()].destination);

        displayFare(travelers[ui->TravelerComboBox->currentIndex()].getPlan());
        displayTotalTime();
        displayPath(travelers[ui->TravelerComboBox->currentIndex()].getPlan());
        displaySpentTime();

        ui->StartButton->setText(QString::fromWCharArray(L"更改"));
        ui->StartComboBox->setEnabled(false);
        ui->StartDateTimeEdit->setEnabled(false);
        ui->ThroughCityCheckBox->setChecked(travelers[ui->TravelerComboBox->currentIndex()].isChecked);
        throughcity = travelers[ui->TravelerComboBox->currentIndex()].throughCity;
        activeThroughCity();

        currentTraveler = ui->TravelerComboBox->currentIndex();
    }
    else
    {
        //当前旅客未执行过构造计划操作,则将界面初始化
        qDebug() << "Change traveler to who possesses no plan, reset the elements in widget";
        ui->StartButton->setText(QString::fromWCharArray(L"开始"));
        ui->StartComboBox->setEnabled(true);
        ui->DestinationComboBox->setEnabled(true);
        ui->StartDateTimeEdit->setEnabled(true);
        ui->DeadlineDateTimeEdit->setEnabled(true);
        ui->ThroughCityCheckBox->setChecked(false);
        throughcity = travelers[ui->TravelerComboBox->currentIndex()].throughCity;
        activeThroughCity();

        ui->StartDateTimeEdit->setDateTime(QDateTime::currentDateTime());
        int deaDay = QDateTime::currentDateTime().date().day();
        deaDay += 1;
        QDateTime deadlineDateTime;
        deadlineDateTime.setDate(QDate(QDateTime::currentDateTime().date().year(), QDateTime::currentDateTime().date().month(), deaDay));
        deadlineDateTime.setTime(QTime(QDateTime::currentDateTime().time()));
        ui->DeadlineDateTimeEdit->setDateTime(deadlineDateTime);
        ui->StrategyComboBox->setCurrentIndex(0);
        ui->StartComboBox->setCurrentIndex(0);
        ui->DestinationComboBox->setCurrentIndex(1);
        QVBoxLayout *listlayout = new QVBoxLayout;
        QWidget *containwidget = new QWidget(ui->PathList);
        containwidget->setLayout(listlayout);
        ui->PathList->setWidget(containwidget);
        ui->FareEdit->clear();
        ui->TotalTimeEdit->clear();
        ui->DurationText->clear();

        currentTraveler = -1;
    }
}
//单击“开始”按钮,获取用户输入信息
void Widget::startButtonClicked()
{
    QDateTime startDateTime;
    //对于当前旅客,初次点击开始按钮
    if (startclicked[ui->TravelerComboBox->currentIndex()] == false)
    {
        qDebug() << "StartButton clicked 1st time for CurrentTraveler";
        strategy = getStrategy();
        start = getStart();
        destination = getDestination();
        //始发地和目的地相同则弹框报错,不作操作
        if (start == destination)
        {
            qDebug() << "Start and Dedtination is the same one, wait for  another command";
            QMessageBox::information(this, "Error", QString::fromWCharArray(L"出发地和目的地相同"));
            return;
        }
        //(策略三的情况下)截止时间早于当前时间报错,不作操作
        if (!(ui->StartDateTimeEdit->dateTime() < ui->DeadlineDateTimeEdit->dateTime()))
        {
            qDebug() << "Deadline ahead of StratTime, wait for another command";
            QMessageBox::information(this, "Error", QString::fromWCharArray(L"截止时间早于当前时间"));
            return;
        }

        startDateTime = getStartTime();

        travelers[ui->TravelerComboBox->currentIndex()] = (Traveler(addtravelertimes-1, startDateTime,
                                                                    getDeadline(), strategy, start, destination, ui->ThroughCityCheckBox->isChecked(), throughcity));
        std::vector<Attribute> path = travelers[ui->TravelerComboBox->currentIndex()].getPlan();
        if (path.size() == 0)
        {
            qDebug() << "No legal path";
            QMessageBox::information(this, "Error", QString::fromWCharArray(L"无有效路径"));
            startclicked[ui->TravelerComboBox->currentIndex()] = false;
            return;
        }

        startclicked[ui->TravelerComboBox->currentIndex()] = true;
        currentTraveler = ui->TravelerComboBox->currentIndex();

        displayTotalTime();
        displayFare(path);
        displayPath(path);

        qDebug() << "StartButton rename as ChangePlan for CurrentTraveler";
        ui->StartButton->setText(QString::fromWCharArray(L"更改"));
        ui->StartComboBox->setEnabled(false);
        ui->StartDateTimeEdit->setEnabled(false);
        startclickedtimes += 1;
        startclicked[ui->TravelerComboBox->currentIndex()] = true;
        return;
    }
    //对于当前旅客,执行更改计划操作
    if (startclicked[ui->TravelerComboBox->currentIndex()] == true)
    {
        qDebug() << "StartButton clicked for CurrentTraveler";
        strategy = getStrategy();
        destination = getDestination();

        if (!(ui->StartDateTimeEdit->dateTime() < ui->DeadlineDateTimeEdit->dateTime()))
        {
            qDebug() << "Deadline ahead of StartTime, reset the DeadlineDateTimeEdit,wait for another command";
            QMessageBox::information(this, "Error", QString::fromWCharArray(L"截止时间早于当前时间"));

            int deaDay = ui->StartDateTimeEdit->dateTime().date().day();
            deaDay += 1;
            QDateTime deadlineDateTime;
            deadlineDateTime.setDate(QDate(ui->StartDateTimeEdit->dateTime().date().year(), ui->StartDateTimeEdit->dateTime().date().month(), deaDay));
            deadlineDateTime.setTime(QTime(ui->StartDateTimeEdit->dateTime().time()));
            ui->DeadlineDateTimeEdit->setDateTime(deadlineDateTime);

            return;
        }

        //获得新计划的始发地,即原计划的当前停留地/运行途中即将到达地
        int nextCity2Arrive = ui->LeftWidget->nextCity();
        if (nextCity2Arrive != -1)
        {
            std::vector<Attribute> path = travelers[ui->TravelerComboBox->currentIndex()].changePlan(nextCity2Arrive, strategy, destination, getDeadline(),
                                                                                                     ui->ThroughCityCheckBox->isChecked(),throughcity);
            if (path.size() == 0)
            {
                qDebug() << "No legal path";
                QMessageBox::information(this, "Error", QString::fromWCharArray(L"无有效路径"));
                return;
            }
            qDebug() << "Change plan success.";
            currentTraveler = ui->TravelerComboBox->currentIndex();
            displayTotalTime();
            displayFare(path);
            displayPath(path);
        }
    }
}