コード例 #1
0
        public static Pathfinder <IDefinitionNodeNetwork, IPathfindNodeNetwork, IPath> Create(PathfindaxManager manager, int threads, bool succesTrue = true)
        {
            return(manager.CreatePathfinder(Substitute.For <IDefinitionNodeNetwork>(), Substitute.For <IPathFindAlgorithm <IPathfindNodeNetwork, IPath> >(), (definitionNodeNetwork, algorithm, cache) =>
            {
                var nodeGrid = Substitute.For <IPathfindNodeNetwork>();
                var nodeArray = new[] { new DefinitionNode(), };
                algorithm.FindPath(null, null).ReturnsForAnyArgs(x =>
                {
                    if (succesTrue)
                    {
                        return new WaypointPath(nodeArray, new[] { 0 }, new Transformer(new Vector2(1, 1)));
                    }
                    else
                    {
                        return null;
                    }
                });

                algorithm.ValidatePath(null, null, null).ReturnsForAnyArgs(x =>
                {
                    return true;
                });
                return PathfinderFactory.CreateRequestProcesser(nodeGrid, algorithm, cache);
            }, Substitute.For <ICache <IPathRequest, IPath> >(), threads));
        }
コード例 #2
0
        // Method to create commands for the drone to execute
        private DroneCommandProcessor createCommands(QualityCheck qc)
        {
            // Get productLocation to take picture from
            ProductLocation pl = qc.ProductLocation;

            // Initiate CommandProcessor
            _droneCommandProcessor = new DroneCommandProcessor();

            // Get Graph datastructure in pathfinder generated from selected warehouse
            IPathfinderFactory pathfinderFactory = new PathfinderFactory();
            Pathfinder         pathfinder        = pathfinderFactory.GetPathfinderFromWarehouse(pl.District.Warehouse);

            // Initiate start position (start position is drone start location)
            Position startNode = new Position(pl.District.Warehouse.StartNode.X, pl.District.Warehouse.StartNode.Y);

            // Get path to take from startposition to nearest graphnode for the Productlocation by using dijkstra algoritm
            LinkedList <Position> path = pathfinder.GetPath(startNode, this.giveEndPosition(pl));

            // save path to qualitycheck for webpage view
            List <Position> path2 = pathfinder.GetPathList(startNode, this.giveEndPosition(pl));
            var             s     = JsonConvert.SerializeObject(path2, Formatting.Indented,
                                                                new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            qc.JSONPath         = s;
            _db.Entry(qc).State = EntityState.Modified;
            _db.SaveChanges();

            // add start / takeoff command to the droneCommandProcessor
            _droneCommandProcessor.AddCommand(new Command {
                name = "Start"
            });

            // add commands to the droneCommandProcessor from path, this generates the commands needed to move to the nearest graphnode to the productlocation
            IMovementCommandFactory mFactory = new MovementCommandFactory();

            _droneCommandProcessor.AddListCommand(mFactory.GetMovementCommands(path));

            // add commands to move from the nearest graphnode to the position in front of the productlocation
            IDistrictCommandFactory dFactory = new DistrictCommandFactory();

            _droneCommandProcessor.AddListCommand(dFactory.GetCommands(giveEndPosition(pl), pl));

            // add command to take picture, this also needs the current quality check id, needed for saving the pictures to the correct location
            _droneCommandProcessor.AddCommand(new Command {
                name = "TakePicture", value = qc.Id
            });

            // add command to land the drone
            _droneCommandProcessor.AddCommand(new Command {
                name = "Land"
            });

            return(_droneCommandProcessor);
        }
コード例 #3
0
        public override IPathfinder <IDefinitionNodeNetwork, IPathfindNodeNetwork <AstarNode>, NodePath> CreatePathfinder()
        {
            var definitionNodeNetwork = GetDefinitionNodeNetwork();

            if (definitionNodeNetwork == null)
            {
                throw new NoDefinitionNodeNetworkException();
            }
            return(PathfinderFactory.CreateAstarPathfinder(PathfindaxDualityCorePlugin.PathfindaxManager, definitionNodeNetwork, MaxClearance, AmountOfThreads));
        }
コード例 #4
0
        public override IPathfinder <DefinitionNodeGrid, DijkstraNodeGrid, PotentialField> CreatePathfinder()
        {
            var definitionNodeNetwork = GetDefinitionNodeNetwork();

            if (definitionNodeNetwork == null)
            {
                throw new NoDefinitionNodeNetworkException();
            }
            return(PathfinderFactory.CreatePotentialFieldPathfinder(PathfindaxDualityCorePlugin.PathfindaxManager, definitionNodeNetwork, MaxClearance, MaxCachedFlowFields, AmountOfThreads));
        }
コード例 #5
0
 public static Pathfinder <IDefinitionNodeNetwork, IPathfindNodeNetwork, IPath> Create(PathfindaxManager manager, int threads, bool succesTrue = true)
 {
     return(manager.CreatePathfinder(Substitute.For <IDefinitionNodeNetwork>(), Substitute.For <IPathFindAlgorithm <IPathfindNodeNetwork, IPath> >(), (definitionNodeNetwork, algorithm) =>
     {
         var nodeGrid = Substitute.For <IPathfindNodeNetwork>();
         var nodeArray = new[] { new DefinitionNode(), };
         algorithm.FindPath(null, null, out var _).ReturnsForAnyArgs(x =>
         {
             x[2] = succesTrue;
             return new NodePath(nodeArray, new[] { 0 }, new Transformer(new Vector2(1, 1)));
         });
         return PathfinderFactory.CreateRequestProcesser(nodeGrid, algorithm);
     }, threads));
 }
コード例 #6
0
 public override IPathfinder <DefinitionNodeGrid, DijkstraNodeGrid, PotentialField> CreatePathfinder()
 {
     try
     {
         var definitionNodeNetwork = GetDefinitionNodeNetwork();
         if (definitionNodeNetwork == null)
         {
             throw new NoDefinitionNodeNetworkException();
         }
         return(PathfinderFactory.CreatePotentialFieldPathfinder(PathfindaxDualityCorePlugin.PathfindaxManager, definitionNodeNetwork, MaxClearance, MaxCachedFlowFields, AmountOfThreads));
     }
     catch (Exception e)
     {
         Logs.Game.WriteError($"Could not generate the definitionnode network. Returning a dummy pathfinder that does nothing. The following error occurred: {LogFormat.Exception(e)}.");
         return(new DummyPathfinder <DefinitionNodeGrid, DijkstraNodeGrid, PotentialField>());
     }
 }
    /// <summary>
    /// Called by UI element. Finds and calls the current pathfinding algorithm if a start and end node are both present.
    /// </summary>
    public void VisualisePath()
    {
        if (startNode != null && endNode != null) // If there is a start AND end node...
        {
            if (pathfinder == null)               // If there is no pathfinder reference...
            {
                pathfinder = PathfinderFactory.GetPathfinder();
            }

            pathfinder.FindPath(startNode.position, endNode.position);
        }
        else // Otherwise...
        {
            grid.StopAllCoroutines();
            grid.UpdateNodeColours();
        }
    }