Example #1
0
        public static NDbResult <List <TSBExchangeGroup> > GetTSBExchangeGroups(TSB tsb,
                                                                                StateTypes state, FinishedFlags flag, DateTime reqBegin, DateTime reqEnd)
        {
            var result          = new NDbResult <List <TSBExchangeGroup> >();
            SQLiteConnection db = Default;

            if (null == db)
            {
                result.DbConenctFailed();
                return(result);
            }
            if (null == tsb)
            {
                result.ParameterIsNull();
                return(result);
            }

            lock (sync)
            {
                MethodBase med = MethodBase.GetCurrentMethod();
                try
                {
                    string cmd = string.Empty;
                    cmd += "SELECT * ";
                    cmd += "  FROM TSBExchangeGroupView ";
                    cmd += " WHERE TSBId = ? ";
                    cmd += "   AND FinishFlag = ? ";
                    if (state != StateTypes.None)
                    {
                        cmd += "   AND State = ? ";
                    }
                    if (reqBegin != DateTime.MinValue)
                    {
                        cmd += "   AND RequestDate >= ? ";
                        if (reqEnd != DateTime.MinValue)
                        {
                            cmd += "   AND RequestDate <= ? ";
                        }
                    }

                    var rets    = NQuery.Query <FKs>(cmd, tsb.TSBId, flag, state, reqBegin, reqEnd).ToList();
                    var results = rets.ToModels();
                    result.Success(results);
                }
                catch (Exception ex)
                {
                    med.Err(ex);
                    result.Error(ex);
                }
                return(result);
            }
        }
Example #2
0
        /// <summary>
        /// Dijkstra pathfinder.
        /// </summary>
        /// <param name="start">The node to begin the search at.</param>
        /// <param name="adj">A function which returns nodes adjacent to the passed in node.</param>
        /// <param name="dist">A function that gives the distance between nodes.</param>
        /// <param name="fin">A function that returns whether or not the node passed in is the end of the search.</param>
        /// <param name="maxnodedepth">The maximum path length.</param>
        /// <returns>A list of paths to the different finishing nodes found.</returns>
        public static List <List <T> > Dijkstra(T start, Adjacent adj, Distance dist, Finished fin, int maxnodedepth)
        {
            Comparison <PathNode <T> >    pwc   = new Comparison <PathNode <T> >(PathWeightCompare);
            PriorityQueue <PathNode <T> > open  = new PriorityQueue <PathNode <T> >(pwc);
            Dictionary <T, double>        bestF = new Dictionary <T, double>();
            List <List <T> > path = new List <List <T> >();

            open.Enqueue(new PathNode <T>(start, null, 0, 0, 0, bestF));
            while (!open.Empty)
            {
                PathNode <T>  cur    = open.Dequeue();
                FinishedFlags isDone = fin(cur.source, cur.g);
                if (isDone != 0)
                {
                    Stack <T> s = new Stack <T>();
                    s.Push(cur.source);
                    while (cur.prevNode != null)
                    {
                        cur = cur.prevNode;
                        s.Push(cur.source);
                    }
                    path.Add(new List <T>());
                    while (s.Count > 0)
                    {
                        path[path.Count - 1].Add(s.Pop());
                    }
                }
                if ((isDone & FinishedFlags.FINISHED) != 0)
                {
                    break;
                }

                List <T> L = adj(cur.source);

                if (maxnodedepth != 0 && cur.nt >= maxnodedepth)
                {
                    continue;
                }

                foreach (T d in L)
                {
                    double ng = cur.g + dist(cur.source, d);
                    if (bestF.ContainsKey(d))
                    {
                        if (ng < bestF[d])
                        {
                            for (int i = 0; i < open.Count; i++)
                            {
                                if (open[i].source.Equals(d))
                                {
                                    open.Remove(i);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    open.Enqueue(new PathNode <T>(d, cur, ng, 0, cur.nt + 1, bestF));
                }
            }
            return(path);
        }