Пример #1
0
    public static void Main(string[] args)
    {
        Node n = BuildExpr();

        if (args.Length != 1)
        {
            Console.WriteLine("Specify 'server' or 'client' as first argument");
            return;
        }

        if (args[0] == "client")
        {
            Ice.IceClientChannel ic = new Ice.IceClientChannel();
            ChannelServices.RegisterChannel(ic);

            NodeEvaluator ne = (NodeEvaluator)Activator.GetObject(typeof(NodeEvaluator),
                                                                  "ice://localhost:10000/ne");

            int res = ne.EvalNode(n);
            Console.WriteLine("Result: {0}", res);
        }
        else if (args[0] == "server")
        {
            Ice.IceChannel ic = new Ice.IceChannel(10000);
            ChannelServices.RegisterChannel(ic);

            RemotingConfiguration.RegisterWellKnownServiceType(typeof(NodeEvaluatorI),
                                                               "ne",
                                                               WellKnownObjectMode.Singleton);
            Console.ReadLine();
        }
    }
Пример #2
0
 public PathFinder(RouteService routeService)
 {
     this.routeService = routeService;
     time = new TimeEvaluator(this);
     cost = new CostEvaluator(this);
     airOnly = new AirOnlyExcluder(this);
     allRoutes = new NullExcluder(this);
 }
            /// <summary>
            ///
            /// </summary>
            void Start()
            {
                m_instance = this; // initialise singleton

                Blackboard[] blackboards = Resources.FindObjectsOfTypeAll <Blackboard>();

                m_blackboards = new List <Blackboard>();
                for (int i = 0; i < blackboards.Length; i++)
                {
                    Blackboard blackboard = ScriptableObject.CreateInstance <Blackboard>();
                    blackboard.Copy(blackboards[i]);
                    m_blackboards.Add(blackboard);
                }

                // retrieve manager from each component
                if (m_audioComponent != null)
                {
                    m_audioManager = m_audioComponent.GetAudioManager();
                }
                if (m_backgroundComponent != null)
                {
                    m_backgroundManager = m_backgroundComponent.GetBackgroundManager();
                }
                if (m_branchComponent != null)
                {
                    m_branchManager = m_branchComponent.GetBranchManager();
                }
                if (m_characterComponent != null)
                {
                    m_characterManager = m_characterComponent.GetCharacterManager();
                }
                if (m_dialogueComponent != null)
                {
                    m_dialogueManager = m_dialogueComponent.GetDialogueManager();
                }
                if (m_logComponent != null)
                {
                    m_logManager = m_logComponent.GetLogManager();
                }
                if (m_saveComponent != null)
                {
                    m_saveManager = new SaveManager(this, m_saveComponent);
                }

                m_utilityManager  = new UtilityManager();
                m_variableManager = new VariableManager();

                m_nodeEvaluator = new NodeEvaluator(this);

                // delete this later
                NewScene(m_startScene);
            }
Пример #4
0
        public DeclaredObjectContainer Parse(string programFile)
        {
            string program = System.IO.File.ReadAllText(programFile);

            var grammar = new BDVHDLGrammar();
            var parser  = new Irony.Parsing.Parser(grammar);
            var ast     = parser.Parse(program);

            if (ast.Status != ParseTreeStatus.Parsed)
            {
                throw new ParserException(programFile, ast.Status, ast.ParserMessages);
            }

            (new TreeConverter()).Convert(ast, grammar);

            var evaluator = new NodeEvaluator();

            evaluator.EvaluateGeneral(ast.Root);

            return(evaluator.declaredObjects);
        }
Пример #5
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;
        }
Пример #6
0
        /*
         * Implements A* search.
         * A custom array based binary heap is used to track the best Open node,
         * and nodes are looked up by direct addresing using their coordinates in the
         * compact nodes array, so we don't need a separate associative container to
         * represent the Closed set.
         */
        public bool Search(Coord start, Coord goal, List<Coord> resultPath, NodeEvaluator costFunc)
        {
            resultPath.Clear();
            if (start.X < 0 || start.Y < 0 || start.X >= width || start.Y >= height)
                return false;
            if (goal.X < 0 || goal.Y < 0 || goal.X >= width || goal.Y >= height)
                return false;
            if (start == goal)
                return true;

            heap.Clear();
            ClearNodes();

            int n = start.Y * width + start.X;
            nodes[n].H = CalcHeuristicDistance(start, goal);
            nodes[n].State = NodeState.Open;
            PushHeap(n);

            while (heap.Count > 0) {
                // examine the best node in the Open set and mark it as Closed
                n = PopHeap();
                nodes[n].State = NodeState.Closed;
                var pos = new Coord(n % width, n / width);

                // are we there yet?
                if (pos == goal) {
                    // walk backward to the start while remembering the coords we pass by
                    do {
                        resultPath.Add(pos);
                        pos += nodes[n].ParentDir.DeltaCoord();
                        n = pos.Y * width + pos.X;
                    } while (pos != start);
                    // reverse it, so the path is in the expected sequence from start to goal
                    resultPath.Reverse();
                    return true;
                }

                // expand all surrounding squares
                for (int d = 0; d < 8; ++d) {
                    var dir = (Direction)d;
                    var fromDir = dir.Opposite();
                    var p = pos + dir.DeltaCoord();

                    if (p.X < 0 || p.Y < 0 || p.X >= width || p.Y >= height)
                        continue;

                    // calc index of node to expand
                    int t = p.Y * width + p.X;

                    // if it is on the ClosedList then we have already examined it
                    if (nodes[t].State == NodeState.Closed)
                        continue;

                    // get the cost of moving into cell t from our direction
                    float cost = dir.StepDistance() * costFunc(p, fromDir) * GScale;
                    if (cost > MaxCost)
                        continue;

                    // add to it the cost of reaching cell n
                    cost += nodes[n].G;

                    if (nodes[t].State == NodeState.Open) {
                        // this node has previously been expanded, but not examined
                        // check to see if this path was a better way to reach it
                        if (cost < nodes[t].G) {
                            // if the new path to this node is better, update cost and
                            // parent then correct the heap according to cost change
                            nodes[t].G = cost;
                            nodes[t].ParentDir = fromDir;
                            UpHeap(nodes[t].Index);
                        }
                    } else {
                        // we've never seen this node before
                        nodes[t].H = CalcHeuristicDistance(p, goal);
                        nodes[t].G = cost;
                        nodes[t].ParentDir = fromDir;
                        nodes[t].State = NodeState.Open;
                        PushHeap(t);
                    }
                }
            }

            return false;
        }
Пример #7
0
        /*
         * Implements A* search.
         * A custom array based binary heap is used to track the best Open node,
         * and nodes are looked up by direct addresing using their coordinates in the
         * compact nodes array, so we don't need a separate associative container to
         * represent the Closed set.
         */
        public bool Search(Coord start, Coord goal, List <Coord> resultPath, NodeEvaluator costFunc)
        {
            resultPath.Clear();
            if (start.X < 0 || start.Y < 0 || start.X >= width || start.Y >= height)
            {
                return(false);
            }
            if (goal.X < 0 || goal.Y < 0 || goal.X >= width || goal.Y >= height)
            {
                return(false);
            }
            if (start == goal)
            {
                return(true);
            }

            heap.Clear();
            ClearNodes();

            int n = start.Y * width + start.X;

            nodes[n].H     = CalcHeuristicDistance(start, goal);
            nodes[n].State = NodeState.Open;
            PushHeap(n);

            while (heap.Count > 0)
            {
                // examine the best node in the Open set and mark it as Closed
                n = PopHeap();
                nodes[n].State = NodeState.Closed;
                var pos = new Coord(n % width, n / width);

                // are we there yet?
                if (pos == goal)
                {
                    // walk backward to the start while remembering the coords we pass by
                    do
                    {
                        resultPath.Add(pos);
                        pos += nodes[n].ParentDir.DeltaCoord();
                        n    = pos.Y * width + pos.X;
                    } while (pos != start);
                    // reverse it, so the path is in the expected sequence from start to goal
                    resultPath.Reverse();
                    return(true);
                }

                // expand all surrounding squares
                for (int d = 0; d < 8; ++d)
                {
                    var dir     = (Direction)d;
                    var fromDir = dir.Opposite();
                    var p       = pos + dir.DeltaCoord();

                    if (p.X < 0 || p.Y < 0 || p.X >= width || p.Y >= height)
                    {
                        continue;
                    }

                    // calc index of node to expand
                    int t = p.Y * width + p.X;

                    // if it is on the ClosedList then we have already examined it
                    if (nodes[t].State == NodeState.Closed)
                    {
                        continue;
                    }

                    // get the cost of moving into cell t from our direction
                    float cost = dir.StepDistance() * costFunc(p, fromDir) * GScale;
                    if (cost > MaxCost)
                    {
                        continue;
                    }

                    // add to it the cost of reaching cell n
                    cost += nodes[n].G;

                    if (nodes[t].State == NodeState.Open)
                    {
                        // this node has previously been expanded, but not examined
                        // check to see if this path was a better way to reach it
                        if (cost < nodes[t].G)
                        {
                            // if the new path to this node is better, update cost and
                            // parent then correct the heap according to cost change
                            nodes[t].G         = cost;
                            nodes[t].ParentDir = fromDir;
                            UpHeap(nodes[t].Index);
                        }
                    }
                    else
                    {
                        // we've never seen this node before
                        nodes[t].H         = CalcHeuristicDistance(p, goal);
                        nodes[t].G         = cost;
                        nodes[t].ParentDir = fromDir;
                        nodes[t].State     = NodeState.Open;
                        PushHeap(t);
                    }
                }
            }

            return(false);
        }