我正在设计一个递归搜索函数,在某些条件下,它将正常递归,而在其他条件下,必须以概率 e^(E/Temperature) 递归。除递归步骤外,所有代码都已完成,因为我无法弄清楚如何根据一定的概率执行某些操作
Node Search(Node start)
{//first, calculate temperature. count will keep timestep
count++;
double temperature = 1000 * (Math.Pow(.995,count));//CALCULATES TEMP
for (int i = 0; i < start.state.Length; i++)
{
string temp = StateReturn(start.state, i);
if (temp.Length > 1 && temp != start.state
&&visited.Contains(temp) == false)
{
list.Add(new Node(start, temp));
visited.Add(temp);
}
}
//add all relevant nodes to list.
Random gen = new Random();
int rand = gen.Next(list.Count);//think this should work
//random number has been taken. now just to pull rand node from list
Node next = list.ElementAt(rand);
list.RemoveAt(rand);
double E = -(next.wrongNum - start.wrongNum); //we want less wrong
// if next has
if (E> 0)
{
//standard recursion
}
else //recurse with probability e^(E/t)
{
}
}