ify"> xTo=new Point (graph.nodes [node2] .GetPositionX (), graph.nodes [node2] .GetPositionY ());
pen=normalPen;
if (pathNodes.Contains (node1) amp; amp; pathNodes.Contains (node2))
pen=linkedPen;
g.DrawLine (pen, xFrom, xTo);
}
for (int i=0; i lt; graph.nodes.Count; i ++)
{
GraphNode node=graph.nodes [i];
if (node.isExists ())
{
NODE_TYPE nodeType=NODE_TYPE.NOT_CONNECTED;// 0 - Not connected, 1 - OK node, 2 - Path node
if (! pathNodes.Contains (i))
foreach (GraphEdge edge in graph.edges)
{
int node1, node2;
edge.GetLinkedNodes (out node1, out node2);
if (node1 == i || node2 == i)
{
nodeType=NODE_TYPE.OK;
break;
}
}
else
nodeType=NODE_TYPE.PATH;
//if (nodeType == NODE_TYPE.OK)
//g.DrawImage (graph.imgOkNode, node.GetPositionX () - graph.imageCenter, node.GetPositionY () - graph.imageCenter);
//else
//g.DrawImage (graph.imgNode, node.GetPositionX () - graph.imageCenter, node.GetPositionY () - graph.imageCenter);
switch (nodeType)
{
case NODE_TYPE.NOT_CONNECTED:
g.DrawImage (graph.imgNode, node.GetPositionX () - graph.imageCenter, node.GetPositionY () - graph.imageCenter);
break;
case NODE_TYPE.OK:
g.DrawImage (graph.imgOkNode, node.GetPositionX () - graph.imageCenter, node.GetPositionY () - graph.imageCenter);
break;
case NODE_TYPE.PATH:
g.DrawImage (imgPathNode, node.GetPositionX () - graph.imageCenter, node.GetPositionY () - graph.imageCenter);
break;
default:
g.DrawImage (graph.imgNode, node.GetPositionX () - graph.imageCenter, node.GetPositionY () - graph.imageCenter);
break;
}
g.DrawString ((i + 1) .ToString (), graph.font, Brushes.Black, node.GetPositionX () - 12, node.GetPositionY () - 12);
}
. Метод GraphMaxDistanceFinder шукає найкоротший шлях між заданими вершинами і повертає true якщо шлях був знайдений і false якщо шлях не існує:
class GraphMaxDistanceFinder
{
struct NodesDistanceEntry
{
public int node1, node2;
public int pathLength;
public NodesDistanceEntry (int n1, int n2, int length)
{
node1=n1;
node2=n2;
pathLength=length;
}
}
Graph graph;
GraphPathFinder pf;
Image imgFoundNode;
List lt; NodesDistanceEntry gt; distanceList;
int maxDistanceInd;
int maxDistanceLength;
public GraphMaxDistanceFinder (ref Graph _graph, string foundNodeImage)
{
graph=_graph;
imgFoundNode=Image.FromFile (foundNodeImage);
pf=new GraphPathFinder (ref graph, foundNodeImage);
distanceList=new List lt; NodesDistanceEntry gt; ();
maxDistanceInd=- 1;
maxDistanceLength=- 1;
}
public bool FoundFarestNodes ()
{
maxDistanceInd=- 1;
maxDistanceLength=- 1;
distanceList.Clear ();
for (int i=0; i lt; graph.nodes.Count - 1; i ++)
{
for (int j=i + 1; j lt; graph.nodes.Count; j ++)
{
if (pf.FindPath (i, j))
{
distanceList.Add (new NodesDistanceEntry (i, j, pf.GetPathLength ()));
}
}
...