سلام مرسی بابت جواب قبلی
من در ادامه همون برنامه به مشکل مشابهی برخوردم
در کد زیر مقدار path را در خط 33 به newRout می دهم. اما از این به بعد زمانی که newRout تغییر می کند path نیز مثل newRout تغییر میکند!!
NotPath=new LinkedList<int>();// include Wi
newRout = new LinkedList<int>();// include Vi
LinkedListNode<int> newNode;
for (int k = 0; k < ObjVertex.Count; k++)
{
if (ObjVertex[k].Occupation == false)
{ NotPath.AddLast(k); }
}
double value=0;
double bestvalue = 0;
int bestBavlueIndex = 0;
bool Flag = false;// this flag determine whethere we have found new Sw for exchange or not
for (int i = 1; i < Path.Count-1; i++)
{
bestvalue = ObjVertex[NotPath.ElementAt<int>(0)].Score - ObjVertex[Path.ElementAt<int>(i)].Score;//best value=sw(0)-sv(i)
Flag = false;
for (int j = 0; j < NotPath.Count; j++)
{
value = ObjVertex[NotPath.ElementAt<int>(j)].Score - ObjVertex[Path.ElementAt<int>(i)].Score; //value= Sw-Sv
if (value > 0 && value > bestvalue)
{
bestvalue = value;
bestBavlueIndex = j;// index of Sw which has the best value
Flag = true;
}
}// of for j
if (Flag == true)// if we have found a Sw with Value > bestvalue
{
//check the total Time of path befor exchange
newRout = Path;//#######################
newNode = newRout.Find(newRout.ElementAt<int>(i));// V vertex from path to be exchanged with W from notpath
newRout.AddAfter(newNode, NotPath.ElementAt<int>(bestBavlueIndex));//adding the W after V
newRout.Remove(newNode);// removing V
if (CalculateTotalTime(newRout) < TMAX)
{
// changing the Occupation property for W and V befor exchange
ObjVertex[Path.ElementAt<int>(i)].Occupation = false;// changing V(i)
ObjVertex[NotPath.ElementAt<int>(bestBavlueIndex)].Occupation = true;// changing w(bestvalue)
//exchanging the V and W in main Path
// Path = newRout;//####################
}
}
else
{
}
}// of for i