public static Edge[] Solve(Graph g, Node start, Node goal)
    {
        // setup sets (1)
        visited   = new List <Node>();
        unvisited = new List <Node>(g.getNodes());

        // set all node tentative distance (2)
        status = new Dictionary <Node, NodeExtension>();
        foreach (Node n in unvisited)
        {
            NodeExtension ne = new NodeExtension();
            ne.distance = (n == start ? 0f : float.MaxValue); // infinite
                                                              // -1 could be a better choice, but would make code more complex later
            status[n] = ne;
        }

        // iterate until all nodes are visited (6)
        while (unvisited.Count > 0)
        {
            // select net current node (3)
            Node current = GetNextNode();

            if (status[current].distance == float.MaxValue)
            {
                break;                                             // graph is partitioned
            }
            // assign weight and predecessor to all neighbors (4)
            foreach (Edge e in g.getConnections(current))
            {
                if (status[current].distance + e.weight < status[e.to].distance)
                {
                    NodeExtension ne = new NodeExtension();
                    ne.distance    = status[current].distance + e.weight;
                    ne.predecessor = e;
                    status[e.to]   = ne;
                }
            }
            // mark current node as visited (5)
            visited.Add(current);
            unvisited.Remove(current);
        }

        if (status[goal].distance == float.MaxValue)
        {
            return(new Edge[0]);                                         // goal is unreachable
        }
        // walk back and build the shortest path (7)
        List <Edge> result = new List <Edge>();
        Node        walker = goal;

        while (walker != start)
        {
            result.Add(status[walker].predecessor);
            walker = status[walker].predecessor.from;
        }
        result.Reverse();
        return(result.ToArray());
    }
        public IList <NodeExtension> Select(NodeExtension data)
        {
            IList <NodeExtension> datos = new List <NodeExtension>();

            try {
                datos = GetHsql(data).List <NodeExtension>();
                if (!Factory.IsTransactional)
                {
                    Factory.Commit();
                }
            }
            catch (Exception e)
            {
                NHibernateHelper.WriteEventLog(WriteLog.GetTechMessage(e));
            }
            return(datos);
        }
        public override IQuery GetHsql(Object data)
        {
            StringBuilder sql           = new StringBuilder("select a from NodeExtension a    where  ");
            NodeExtension nodeextension = (NodeExtension)data;

            if (nodeextension != null)
            {
                Parms = new List <Object[]>();
                if (nodeextension.RowID != 0)
                {
                    sql.Append(" a.RowID = :id     and   ");
                    Parms.Add(new Object[] { "id", nodeextension.RowID });
                }

                if (nodeextension.Node != null && nodeextension.Node.NodeID != 0)
                {
                    sql.Append(" a.Node.NodeID = :id1     and   ");
                    Parms.Add(new Object[] { "id1", nodeextension.Node.NodeID });
                }

                if (!String.IsNullOrEmpty(nodeextension.FieldName))
                {
                    sql.Append(" a.FieldName = :nom     and   ");
                    Parms.Add(new Object[] { "nom", nodeextension.FieldName });
                }

                if (!String.IsNullOrEmpty(nodeextension.FieldType))
                {
                    sql.Append(" a.FieldType = :nom1     and   ");
                    Parms.Add(new Object[] { "nom1", nodeextension.FieldType });
                }

                if (nodeextension.Size != 0)
                {
                    sql.Append(" a.Size = :id2     and   ");
                    Parms.Add(new Object[] { "id2", nodeextension.Size });
                }
            }

            sql = new StringBuilder(sql.ToString());
            sql.Append("1=1 order by a.RowID asc ");
            IQuery query = Factory.Session.CreateQuery(sql.ToString());

            SetParameters(query);
            return(query);
        }
 public Boolean Delete(NodeExtension data)
 {
     return(base.Delete(data));
 }
 public NodeExtension SelectById(NodeExtension data)
 {
     return((NodeExtension)base.SelectById(data));
 }
 public Boolean Update(NodeExtension data)
 {
     return(base.Update(data));
 }
 public NodeExtension Save(NodeExtension data)
 {
     return((NodeExtension)base.Save(data));
 }
Example #8
0
    public static Edge[] Solve(Graph g, Node start, Node goal, HeuristicFunction heuristic)
    {
        // setup sets (1)
        visited   = new List <Node>();
        unvisited = new List <Node> (g.getNodes());

        // set all node tentative distance (2)
        status = new Dictionary <Node, NodeExtension> ();
        foreach (Node n in unvisited)
        {
            NodeExtension ne = new NodeExtension();
            ne.distance = (n == start ? 0f : float.MaxValue);               // infinite
            ne.estimate = (n == start ? heuristic(start, goal) : float.MaxValue);
            status [n]  = ne;
        }

        // iterate until goal is reached with an optimal path (6)
        while (!CheckSearchComplete(goal, unvisited))
        {
            // select net current node (3)
            Node current = GetNextNode();

            if (status [current].distance == float.MaxValue)
            {
                break;                                                          // graph is partitioned
            }
            // assign weight and predecessor to all neighbors (4)
            foreach (Edge e in g.getConnections(current))
            {
                if (status[current].distance + e.weight < status[e.to].distance)
                {
                    NodeExtension ne = new NodeExtension();
                    ne.distance    = status[current].distance + e.weight;
                    ne.estimate    = ne.distance + heuristic(start, e.to);
                    ne.predecessor = e;
                    status[e.to]   = ne;
                    // unlike Dijkstra's, we can now discover better paths
                    if (visited.Contains(e.to))
                    {
                        unvisited.Add(e.to);
                        visited.Remove(e.to);
                    }
                }
            }
            // mark current node as visited (5)
            visited.Add(current);
            unvisited.Remove(current);
        }

        if (status [goal].distance == float.MaxValue)
        {
            return(new Edge[0]);                                                  // goal is unreachable
        }
        // walk back and build the shortest path (7)
        List <Edge> result = new List <Edge> ();
        Node        walker = goal;

        while (walker != start)
        {
            result.Add(status [walker].predecessor);
            walker = status [walker].predecessor.from;
        }
        result.Reverse();
        return(result.ToArray());
    }
Example #9
0
 public void DeleteNodeExtension(NodeExtension data)
 {
     try {
     SetService();  SerClient.DeleteNodeExtension(data); }
     finally
     {
         SerClient.Close();
         if (SerClient.State == CommunicationState.Faulted)
         SerClient.Abort(); 
     }
 }
Example #10
0
 public NodeExtension SaveNodeExtension(NodeExtension data)
 {
     try {
     SetService();  return SerClient.SaveNodeExtension(data); }
     finally
     {
         SerClient.Close();
         if (SerClient.State == CommunicationState.Faulted)
         SerClient.Abort(); 
     }
 }