示例#1
0
void Travel(int v,int s,int** par)
{
	way.push_back((v));
	if (v == s)
	{
		
		//cout << v + 1 << " ";
	}
	else
	{
		Travel(par[s][v],s,par);
		//cout << v +1 << " ";
	}
}
示例#2
0
int main()
{
	s--; f--;
	vector<TrainLeg> AllTrain(read());//считывание xml файла
	//AllTrain[0].ShowAll();
	vector<int> arrayNumStantion(CountStantion(AllTrain));//массив всех доступных станций
	cout << "Stantion:";
	for (int i = 0; i < arrayNumStantion.size();++i)
	{
		cout<<arrayNumStantion[i]<<" ";
	}
	//
	float **graphCost = new float*[arrayNumStantion.size()];//матрица стоимости
	for (int count = 0; count < arrayNumStantion.size(); count++)
		graphCost[count] = new float[arrayNumStantion.size()]; 
	int **next = new int*[arrayNumStantion.size()];//массив предков для восстановления пути
	for (int count = 0; count < arrayNumStantion.size(); count++)
		next[count] = new int[arrayNumStantion.size()];

	//
	//инициализация максимумами
	for (int i = 0; i < arrayNumStantion.size(); ++i)
		for (int j = 0; j < arrayNumStantion.size(); ++j)
			graphCost[i][j] = MAX;

	//
	for (int i = 0; i < arrayNumStantion.size(); ++i)
		for (int j = 0; j < arrayNumStantion.size(); ++j)
		{
			next[i][j] = i;
			if (i == j)
			{
				graphCost[i][j] = 0;
				continue;
			}
			int ind = find_train_minprice(AllTrain, arrayNumStantion[i], arrayNumStantion[j]);
			if (ind != -1)
			{
				graphCost[i][j] = AllTrain[ind].getPrice();
				continue;
			}
		}
	//
	cout << endl<<endl<<endl;
	cout << "Initial Matrix: "<<endl;
	for (int i = 0; i < arrayNumStantion.size(); ++i,cout<<endl)
		for (int j = 0; j < arrayNumStantion.size(); ++j)
			cout << graphCost[i][j] << "\t";

	int n = arrayNumStantion.size();
	Floyd(graphCost, next, n);
	//
	cout << endl << endl << endl;
	if (graphCost[s][f] < MAX)
	{
		cout << "Way " << arrayNumStantion[f] << " -> " << arrayNumStantion[s]<<endl;
		cout<<"MIN Price = ";
		cout << graphCost[s][f] << endl;
		Travel(s, f, next);
		cout << "All way: ";
		for (int i = way.size()-1; i >=0 ; --i)
			cout <<arrayNumStantion[way[i]]<<" ";
	}
	else
	{
		cout << "Way " << arrayNumStantion[f] << " -> " << arrayNumStantion[s]<< "not found"<<endl;
	}
	//
	cout << endl << endl << endl;
	cout << "Matrix min price:" << endl;
	for (int i = 0; i < arrayNumStantion.size(); ++i, cout << endl)
		for (int j = 0; j < arrayNumStantion.size(); ++j)
			cout << graphCost[i][j] << "\t";
	system("pause");
	return 0;
}
	void LinearActuatorNoPot::run() {
		runned();

		if (_state == ActuatorState_Initializing)
		{
			_runTime = millis() - _lastTime;
			if (Travel() > _actuatorLength)
			{
				enabled = false;
				_currentPosition = 0;
				Stop();
				Serial.println(_name + F(" actuator retracted and initialized"));
			}
		}
		else
		{
			float currentAngle = CurrentAngleFlipped();
			float delta = abs(currentAngle - _requestedAngle);
			Serial.print(_name + F(" tracking currentAngle: "));
			Serial.print(currentAngle);
			Serial.print(F(" _requestedAngle: "));
			Serial.print(_requestedAngle);
			Serial.print(F(" delta: "));
			Serial.print(delta);
			Serial.print(F(" _currentPosition: "));
			Serial.println(_currentPosition);
			if (delta <= histeresis)
			{
				Stop();
				Serial.println(_name + F(" actuator tracking complete "));
			}
			else if (currentAngle < _requestedAngle)
			{
				if (_state != ActuatorState_MovingOut)
				{
					MoveOut();
					_lastTime = millis();
					Serial.println(_name + F(" actuator MoveOut "));
				}
			}
			else if (currentAngle > _requestedAngle)
			{
				if (_state != ActuatorState_MovingIn)
				{
					MoveIn();
					_lastTime = millis();
					Serial.println(_name + F(" actuator MoveIn "));
				}
			}
			long now = millis();
			_runTime = now - _lastTime;
			_lastTime = now;
			if (_state == ActuatorState_MovingOut)
			{
				_currentPosition += Travel(); // inch step ((time in millis * 1000)  * speed
			}
			else if (_state == ActuatorState_MovingIn)
			{
				_currentPosition -= Travel(); // inch step ((time in millis * 1000)  * speed
			}
		}
	}