ign="justify">}
//returns an unvisited vertex adj to vint getAdjUnvisitedVertex (int v) {(int j=0; j lt; nVerts; j ++) (adjMat [v] [j] == 1 amp; amp ; vertexList [j]. wasVisited == false)
return j;- 1;
}
}
}
Perl
while (!queue) # поки черга не порожня
{
for my $ key (keys% graph) # біжимо по ключам (вершина - ключ)
{@ queue, $ key; # Додаємо перше вершину (стартову) і так далі (2,3,4)
$ state {$ key}= SERIY raquo ;; # Мітимо її, як переглянуту (0. Scalar @ {$ graph {$ key}} - 1) # біжимо по суміжних вершин
{
$ p=shiftqueue; # Витягаємо першу вершину @ queue, $ graph {$ key} [$ _]; # Додаємо суміжні вершини ($ state {$ graph {$ key} [$ _]} eq SERIY ) # якщо ми вже переглядали вершину, то існує цикл
{ cicle
}
{
$ state {$ graph {$ key} [$ _]}= SERIY raquo ;; # Інакше мітимо вершину
}
}
}
}
Java
package problemresolver. algorithm. base;
import problemresolver. world. Path;
public interface TreeSearchContainer
{
void push (Path path); pop (); peek ();
boolean isEmpty ();
}
package problemresolver. algorithm. base;
import edu. uci. ics. jung. graph. util. Pair;
import problemresolver. algorithm. *;
import problemresolver. algorithm. model. *;
import problemresolver. algorithmntime. *;
import problemresolver. world. *;
import java. util. ArrayList;
import java. util. Collection;
public abstract class TreeSearch
extends Algorithm
{
private TreeSearchContainer fringe;
@ Override
protected void safeRun (AlgorithmModel model)
throws AlgorithmException, AlgorithmRuntimeException
{saModel =. castToSingleAgentAlgorithmModel (model);. checkSingleAgentAlgorithmModel (saModel); agent=saModel. getAgentLocation ();
agent. setMark (WorldElement. MarkType. Visited);
fringe=createContainer ();
fringe. push ( new Path (agent));
setRuned ( true );
}
protected abstract TreeSearchContainer createContainer ();
@ Override
protected void safeDoStep ()
throws AlgorithmException, AlgorithmRuntimeException
{
if (fringe. isEmpty ())
{();
return ;
} path=fringe. pop ();
Collection lt; Path gt; successors=expand (path);
for (Path successor: successors)
{successorTail=successor. tail (); successorResident=successorTail. getResident ();
if (successorResident!= null amp; amp;
successorResident. getType () == Unit. Type. Goal)
{();
successor. mark (WorldElement. MarkType. Step);
}
else
{
successorTail. setMark (WorldElement. MarkType. Visited);
if (successorResident == null ||
successorResident. getType ()! =Unit. Type. Obstacle)
{. push (successor);
}
}
}
}
private Collection lt; Path gt; expand (Path path)