コード例 #1
0
ファイル: RouteMapShould.cs プロジェクト: halcwb/GenForm
 public void BeAssociatedWithShapes()
 {
     var comparer = new RouteComparer();
     new PersistenceSpecification<Route>(Context.CurrentSession(), comparer)
         .CheckProperty(r => r.Name, "intraveneus")
         .CheckProperty(r => r.Abbreviation, "iv")
         .CheckList(r => r.ShapeSet, GetShapesList(), (route, shape) => route.AddShape(shape))
         .VerifyTheMappings();
 }
コード例 #2
0
        public void BeAssociatedWithShapes()
        {
            var comparer = new RouteComparer();

            new PersistenceSpecification <Route>(Context.CurrentSession(), comparer)
            .CheckProperty(r => r.Name, "intraveneus")
            .CheckProperty(r => r.Abbreviation, "iv")
            .CheckList(r => r.ShapeSet, GetShapesList(), (route, shape) => route.AddShape(shape))
            .VerifyTheMappings();
        }
コード例 #3
0
 public static void MyClassInitialize(TestContext testContext)
 {
     _comparer = new RouteComparer();
 }
コード例 #4
0
        //, Excluder excluder)
        private List<RouteInstance> findPath(DateTime requestTime, RouteNode origin, RouteNode goal, int weight, int volume, NodeEvaluator evaluator, RouteExcluder excluder)
        {
            Delivery delivery = new Delivery();
            delivery.Origin = origin;
            delivery.Destination = goal;
            delivery.WeightInGrams = weight;
            delivery.VolumeInCm3 = volume;
            delivery.TimeOfRequest = requestTime;

            originPath = new Dictionary<RouteNode, RouteInstance>();
            nodeCost = new Dictionary<RouteNode, double>();
            closed = new HashSet<RouteNode>();
            var rc = new RouteComparer();
            fringe = new SortedList<RouteNode, double>(rc);

            fringe.Add(origin, 0);
            originPath.Add(origin, new OriginRouteInstance(requestTime));

            //if the queue is empty return null (no path)
            while (fringe.Count > 0)
            {
                //take new node off the top of the stack
                //this is guaranteed to be the best way to the node
                RouteNode curNode = fringe.Keys[0];

                if (closed.Contains(curNode))
                    continue;

                nodeCost.Add(curNode, fringe.Values[0]);
                closed.Add(curNode);
                fringe.RemoveAt(0);

                //if it's the goal node exit and return path
                if (curNode.Equals(goal))
                    return completeDelivery(curNode);

                //grab a list of all of the routes where the given node is the origin
                IEnumerable<Route> routes = routeService.GetAll(curNode);

                //take each route that hasn't been ommited and evaluate
                foreach (Route path in excluder.Omit(routes))
                {
                    RouteInstance nextInstance = evaluator.GetNextInstance(path);
                    RouteNode nextNode = path.Destination;

                    double totalCost = evaluator.GetValue(nextInstance, delivery);

                    //if the node is not in the fringe
                    //or the current value is lower than
                    //the new cost then set the new parent
                    if (!fringe.ContainsKey(nextNode))
                    {
                        originPath.Add(nextNode, nextInstance);
                        fringe.Add(nextNode, totalCost);
                    }
                    else if (fringe[nextNode] > totalCost)
                    {
                        originPath.Remove(nextNode);
                        fringe.Remove(nextNode);

                        originPath.Add(nextNode, nextInstance);
                        fringe.Add(nextNode, totalCost);
                    }
                }
            }
            return null;
        }
コード例 #5
0
 public static void MyClassInitialize(TestContext testContext)
 {
     _comparer = new RouteComparer();
 }