public List <Node> AllTogetherPathfind(ReservationTable resT, Vector3 StartPosition, Vector3 EndPosition)
    {
        Node        LastNode     = SilverPathAssess(this_gridClass, StartPosition, EndPosition);
        List <Node> Optimalpath1 = RetracePath(this_gridClass, StartPosition, LastNode.WorldPosition);
        List <Node> path1        = PathFinding(Optimalpath1, resT, this_tableSize, this_gridClass, StartPosition, EndPosition);

        return(path1);
    }
Example #2
0
        public T Select <T>(T type, int primaryKey) where T : new()
        {
            Type entType = type.GetType();

            if (entType == typeof(City))
            {
                return((T)Convert.ChangeType(CityTable.Select(primaryKey), typeof(T)));
            }

            if (entType == typeof(Customer))
            {
                return((T)Convert.ChangeType(CustomerTable.Select(primaryKey), typeof(T)));
            }

            if (entType == typeof(Distillation))
            {
                return((T)Convert.ChangeType(DistillationTable.Select(primaryKey), typeof(T)));
            }

            if (entType == typeof(District))
            {
                return((T)Convert.ChangeType(DistrictTable.Select(primaryKey), typeof(T)));
            }

            if (entType == typeof(Material))
            {
                return((T)Convert.ChangeType(MaterialTable.Select(primaryKey), typeof(T)));
            }

            if (entType == typeof(Period))
            {
                return((T)Convert.ChangeType(PeriodTable.Select(primaryKey), typeof(T)));
            }

            if (entType == typeof(Region))
            {
                return((T)Convert.ChangeType(RegionTable.Select(primaryKey), typeof(T)));
            }

            if (entType == typeof(Reservation))
            {
                return((T)Convert.ChangeType(ReservationTable.Select(primaryKey), typeof(T)));
            }

            if (entType == typeof(Season))
            {
                return((T)Convert.ChangeType(SeasonTable.Select(primaryKey), typeof(T)));
            }

            if (entType == typeof(UserInfo))
            {
                return((T)Convert.ChangeType(UserInfoTable.Select(primaryKey), typeof(T)));
            }

            return(default(T));
        }
Example #3
0
        public ICollection <T> SelectAll <T>(T type) where T : new()
        {
            Type entType = type.GetType();

            if (entType == typeof(City))
            {
                return((ICollection <T>)CityTable.Select());
            }

            if (entType == typeof(Customer))
            {
                return((ICollection <T>)CustomerTable.Select());
            }

            if (entType == typeof(Distillation))
            {
                return((ICollection <T>)DistillationTable.Select());
            }

            if (entType == typeof(District))
            {
                return((ICollection <T>)DistrictTable.Select());
            }

            if (entType == typeof(Material))
            {
                return((ICollection <T>)MaterialTable.Select());
            }

            if (entType == typeof(Period))
            {
                return((ICollection <T>)PeriodTable.Select());
            }

            if (entType == typeof(Region))
            {
                return((ICollection <T>)RegionTable.Select());
            }

            if (entType == typeof(Reservation))
            {
                return((ICollection <T>)ReservationTable.Select());
            }

            if (entType == typeof(Season))
            {
                return((ICollection <T>)SeasonTable.Select());
            }

            if (entType == typeof(UserInfo))
            {
                return((ICollection <T>)UserInfoTable.Select());
            }

            return(null);
        }
Example #4
0
        public int Insert <T>(T entity)
        {
            Type type = entity.GetType();

            if (type == typeof(City))
            {
                return(CityTable.Insert(entity as City));
            }

            if (type == typeof(Customer))
            {
                return(CustomerTable.Insert(entity as Customer));
            }

            if (type == typeof(Distillation))
            {
                return(DistillationTable.Insert(entity as Distillation));
            }

            if (type == typeof(District))
            {
                return(DistrictTable.Insert(entity as District));
            }

            if (type == typeof(Material))
            {
                return(MaterialTable.Insert(entity as Material));
            }

            if (type == typeof(Period))
            {
                return(PeriodTable.Insert(entity as Period));
            }

            if (type == typeof(Region))
            {
                return(RegionTable.Insert(entity as Region));
            }

            if (type == typeof(Reservation))
            {
                return(ReservationTable.Insert(entity as Reservation));
            }

            if (type == typeof(Season))
            {
                return(SeasonTable.Insert(entity as Season));
            }

            if (type == typeof(UserInfo))
            {
                return(UserInfoTable.Insert(entity as UserInfo));
            }

            return(0);
        }
Example #5
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="graph">graph</param>
 /// <param name="seed">The seed to use for the randomizer.</param>
 /// <param name="logger">The logger to use.</param>
 public PASMethod(Graph graph, int seed, PathPlanningCommunicator logger)
     : base(graph, seed, logger)
 {
     if (graph.BackwardEdges == null)
     {
         graph.GenerateBackwardEgdes();
     }
     rraStars          = new Dictionary <int, ReverseResumableAStar>();
     _reservationTable = new ReservationTable(graph, true, true, true);
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FARMethod"/> class.
 /// </summary>
 /// <param name="graph">graph</param>
 /// <param name="seed">The seed to use for the randomizer.</param>
 /// <param name="logger">The logger to use.</param>
 public BCPMethod(Graph graph, int seed, PathPlanningCommunicator logger)
     : base(graph, seed, logger)
 {
     if (graph.BackwardEdges == null)
     {
         graph.GenerateBackwardEgdes();
     }
     _reservationTable = new ReservationTable(graph, true, true, false);
     _biasedCost       = new Dictionary <int, Dictionary <int, double> >();
     _deadlockHandler  = new DeadlockHandler(graph, seed);
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FARMethod"/> class.
 /// </summary>
 /// <param name="graph">graph</param>
 /// <param name="seed">The seed to use for the randomizer.</param>
 /// <param name="logger">The logger to use.</param>
 public CBSMethod(Graph graph, int seed, PathPlanningCommunicator logger)
     : base(graph, seed, logger)
 {
     if (graph.BackwardEdges == null)
     {
         graph.GenerateBackwardEgdes();
     }
     _reservationTable      = new ReservationTable(graph);
     _agentReservationTable = new ReservationTable(graph, false, true, false);
     _deadlockHandler       = new DeadlockHandler(graph, seed);
 }
        /// <summary>
        /// Finds the paths.
        /// </summary>
        /// <param name="currentTime">The current time.</param>
        /// <param name="agents">The agents.</param>
        /// <param name="obstacleNodes">The obstacle nodes.</param>
        /// <param name="lockedNodes">The locked nodes.</param>
        /// <returns></returns>
        public List <IndependenceDetection.PlannedPath> FindPaths(List <Agent> agents)
        {
            //set data
            this.Clear(0, -1);
            this._agents     = agents;
            this._stopSearch = false;

            //clear data structures
            NodeBackpointerId.Clear();
            NodeCreatedByAgent.Clear();
            NodeStepNode.Clear();
            _hValues.Clear();
            _gValues.Clear();
            _reservationTable = new ReservationTable(_graph, true);

            //initiate data structures
            var plannedPaths = new List <IndependenceDetection.PlannedPath>();

            //create one A* node generator per agent
            foreach (var agent in agents)
            {
                _nodeGenerator[agent.ID].Clear();
            }

            //add first Node
            LastNodeId = 0;
            NodeBackpointerId.Add(-1);
            NodeCreatedByAgent.Add(null);
            NodeStepNode.Add(-1);
            _hValues.Add(_agents.Sum(a => _nodeGenerator[a.ID].h(0)));
            _gValues.Add(0.0);

            _minHValue    = _hValues[0];
            _minHNode     = 0;
            _minHTime     = 0;
            _maxNodeCount = _maxNodeCountPerAgent * agents.Count;

            //execute the search
            this.Search();

            //get the result
            foreach (var agent in agents)
            {
                var plannedPath = new IndependenceDetection.PlannedPath();
                plannedPath.Agent = agent;
                plannedPath.Path  = new Path();
                _nodeGenerator[agent.ID].GetPathAndReservations(ref plannedPath.Path, out plannedPath.Reservations);
                plannedPaths.Add(plannedPath);
            }

            return(plannedPaths);
        }
Example #9
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="graph">graph</param>
 /// <param name="seed">The seed to use for the randomizer.</param>
 /// <param name="logger">The logger to use.</param>
 public WHCAvStarMethod(Graph graph, int seed, PathPlanningCommunicator logger)
     : base(graph, seed, logger)
 {
     if (graph.BackwardEdges == null)
     {
         graph.GenerateBackwardEgdes();
     }
     rraStars          = new Dictionary <int, ReverseResumableAStar>();
     _reservationTable = new ReservationTable(graph);
     if (UseDeadlockHandler)
     {
         _deadlockHandler = new DeadlockHandler(graph, seed);
     }
 }
//---------------------pathfinding----------------------//

    public List <Node> PathFinding(List <Node> optimalPath, ReservationTable resT, int tableSize, Grid gridClass, Vector3 StartPosition, Vector3 EndPosition)
    {
        Node currentNode = gridClass.NodeFromWorldPoint(StartPosition);
        Node endNode     = gridClass.NodeFromWorldPoint(EndPosition);

        currentNode.hCost = GetDistance(currentNode, endNode);

        List <Node> realPath = new List <Node>();

        for (int time = 0; time < tableSize; time++)
        {
            if (time > optimalPath.Count - 1)
            {
                break;
            }
            //to solve head to head
            resT.Reserve(time, currentNode);
            //---------------------------------------------------------------
            List <Node> notOptimal = new List <Node> ();
            foreach (Node neighbour in gridClass.GetNeighbors(currentNode))
            {
                neighbour.hCost = GetDistance(neighbour, endNode);

                if (!resT.CheckReserve(time, neighbour) && optimalPath [time] == (neighbour))
                {
                    currentNode = neighbour;
                    notOptimal  = new List <Node> ();
                    break;
                }
                else if (!resT.CheckReserve(time, neighbour))
                {
                    notOptimal.Add(neighbour);
                }
            }
            if (notOptimal.Count > 0)
            {
                Node subOptimal = BestNodeFromList(notOptimal, gridClass);
                if (currentNode.hCost > subOptimal.hCost)
                {
                    currentNode = subOptimal;
                }
            }
            realPath.Add(currentNode);
            //reserve
            resT.Reserve(time, currentNode);
        }
        return(realPath);
//		return optimalPath;
    }
Example #11
0
        static void Main(string[] args)
        {
            //Configuration.SetDbConnection(
            //  DataLayerNetCore.DBType.XmlDatabase,
            //  @"C:\Users\Vojtěch\Source\Repos\VIS_projekt\Aplikace\DistilleryDbLib\WebApp\DistXml.xml");


            DBFactory.configuredDbType           = DBType.SqlServer;
            DBFactory.configuredConnectionString = @"data source = dbsys.cs.vsb.cz\STUDENT; initial catalog = mor0146; user id = mor0146; password = Wt0pEzMOWp";

            var list = ReservationTable.Select();
            var one  = ReservationTable.Select(1);

            //Console.WriteLine(one.District);
        }
        public async Task <IActionResult> TablesCreate(int tableId, int reservationId)
        {
            try
            {
                var rt = new ReservationTable {
                    TableId = tableId, ReservationId = reservationId
                };
                _context.ReservationTables.Add(rt);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Tables), new { id = reservationId }));
            }
            catch (Exception)
            {
                return(RedirectToAction(nameof(Tables), new { id = reservationId }));
            }
        }
Example #13
0
        private void POST_Create_Reservation()
        {
            //TO-DO fix validation for input fields
            if (!UserAgent.IsAuthenticated)
            {
                return;
            }

            if (UserAgent.Account.Contact.MissingData())
            {
                return;
            }

            Reservation res = ReservationTable.CreateReservation(UserAgent.Account.Id, restaurant, DateTime.Parse(fromdate + " " + fromtime), DateTime.Parse(tilldate + " " + tilltime), guestsamount);

            NotificationTable.CreateNotification(UserAgent.Account.Id, AccountTable.RetrieveAccountByCompanyID(restaurant).Id, res.Id, 2);
        }
Example #14
0
        /// <summary>
        /// Initializes the reservation table.
        /// </summary>
        private void _initReservationTable()
        {
            _reservationTable = new ReservationTable(PathFinder.Graph, true);

            //lasy initialization reservations
            _reservations = new Dictionary <BotNormal, List <ReservationTable.Interval> >();
            foreach (BotNormal bot in Instance.Bots)
            {
                if (bot.CurrentWaypoint == null)
                {
                    bot.CurrentWaypoint = bot.Instance.WaypointGraph.GetClosestWaypoint(bot.Instance.Compound.BotCurrentTier[bot], bot.X, bot.Y);
                }

                _reservations.Add(bot, new List <ReservationTable.Interval>());
                _reservations[bot].Add(new ReservationTable.Interval(_waypointIds[bot.CurrentWaypoint], 0, double.PositiveInfinity));
                _reservationTable.Add(_reservations[bot][0]);
            }
        }
Example #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SpaceTimeAStar"/> class.
        /// </summary>
        public SpaceTimeAStar(Graph graph, double lengthOfAWaitStep, double lengthOfAWindow, ReservationTable reservationTable, Agent agent, ReverseResumableAStar rraStar, bool tieBreaking = true)
            : base(0, -1)
        {
            this._graph             = graph;
            this._lengthOfAWaitStep = lengthOfAWaitStep;
            this._lengthOfAWindow   = lengthOfAWindow;
            this._reservationTable  = reservationTable;
            this._agent             = agent;
            this._RRAStar           = rraStar;
            this._tieBreaking       = tieBreaking;

            //built mappings
            NodeTime                      = new List <double>();
            NodeBackpointerId             = new List <int>();
            NodeBackpointerLastStopId     = new List <int>();
            NodeBackpointerEdge           = new List <Edge>();
            NodeTimeTemp                  = new List <double>();
            NodeBackpointerIdTemp         = new List <int>();
            NodeBackpointerLastTurnIdTemp = new List <int>();
            NodeBackpointerEdgeTemp       = new List <Edge>();

            StartAngle = Graph.RadToDegree(agent.OrientationAtNextNode);

            NodeTime.Add(agent.ArrivalTimeAtNextNode);
            NodeBackpointerId.Add(-1);
            NodeBackpointerLastStopId.Add(0);
            NodeBackpointerEdge.Add(null);
            _numNodeId++;

            _init = true;

            //the node 0 has no assigned value yet.
            Q.ChangeKey(Open[0], h(0));

            if (_tieBreaking)
            {
                _tieBreakingTimes = new double[graph.NodeCount];

                for (var i = 0; i < _tieBreakingTimes.Length; i++)
                {
                    _tieBreakingTimes[i] = -1.0;
                }
            }
        }
Example #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FARMethod"/> class.
        /// </summary>
        /// <param name="graph">graph</param>
        /// <param name="seed">The seed to use for the randomizer.</param>
        /// <param name="logger">The logger to use.</param>
        public FARMethod(Graph graph, int seed, EvadingStrategy evadingStragety, PathPlanningCommunicator logger)
            : base(graph, seed, logger)
        {
            _evadingStragety = evadingStragety;

            if (graph.BackwardEdges == null)
            {
                graph.GenerateBackwardEgdes();
            }

            _waitFor          = new Dictionary <int, int>();
            _reservationTable = new ReservationTable(graph, false, true, false);
            _rraStar          = new Dictionary <int, ReverseResumableAStar>();
            _moveTime         = new Dictionary <int, double>();
            _waitTime         = new Dictionary <int, double>();
            _es2evadedFrom    = new Dictionary <int, HashSet <int> >();
            if (UseDeadlockHandler)
            {
                _deadlockHandler = new DeadlockHandler(graph, seed);
            }
        }
Example #17
0
        /// <summary>
        /// Randoms the hop.
        /// </summary>
        /// <param name="agent">The agent.</param>
        /// <param name="reservationTable">The reservation table.</param>
        /// <param name="currentTime">The current time.</param>
        /// <param name="finalReservation">if set to <c>true</c> [final reservation].</param>
        /// <param name="insertReservation">if set to <c>true</c> [insert reservation].</param>
        /// <returns></returns>
        public bool RandomHop(Agent agent, ReservationTable reservationTable = null, double currentTime = 0.0, bool finalReservation = false, bool insertReservation = false)
        {
            //try to find a free hop
            var possibleEdges = new List <Edge>(_graph.Edges[agent.NextNode]);

            shuffle <Edge>(possibleEdges);
            foreach (var edge in possibleEdges.Where(e => !e.ToNodeInfo.IsLocked && (agent.CanGoThroughObstacles || !e.ToNodeInfo.IsObstacle)))
            {
                //create intervals
                if (reservationTable != null)
                {
                    var intervals = reservationTable.CreateIntervals(currentTime, currentTime, 0, agent.Physics, agent.NextNode, edge.To, finalReservation);

                    //check if a reservation is possible
                    if (reservationTable.IntersectionFree(intervals))
                    {
                        if (insertReservation)
                        {
                            reservationTable.Add(intervals);
                        }

                        //create a path
                        agent.Path.Clear();
                        agent.Path.AddLast(edge.To, true, _rnd.NextDouble() * LengthOfAWaitStep);

                        return(true);
                    }
                }
                else
                {
                    //create a path
                    agent.Path.Clear();
                    agent.Path.AddLast(edge.To, true, _rnd.NextDouble() * LengthOfAWaitStep);

                    return(true);
                }
            }

            return(false);
        }
Example #18
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="graph">graph</param>
        /// <param name="seed">The seed to use for the randomizer.</param>
        /// <param name="logger">The logger to use.</param>
        public WHCAnStarMethod(Graph graph, int seed, List <int> agentIds, List <int> startIds, PathPlanningCommunicator logger)
            : base(graph, seed, logger)
        {
            if (graph.BackwardEdges == null)
            {
                graph.GenerateBackwardEgdes();
            }
            rraStars          = new Dictionary <int, ReverseResumableAStar>();
            _reservationTable = new ReservationTable(graph, true, false, false);


            _calculatedReservations = new Dictionary <int, List <ReservationTable.Interval> >();
            for (var i = 0; i < agentIds.Count; i++)
            {
                _calculatedReservations.Add(agentIds[i], new List <ReservationTable.Interval>(new ReservationTable.Interval[] { new ReservationTable.Interval(startIds[i], 0, double.PositiveInfinity) }));
                _reservationTable.Add(_calculatedReservations[agentIds[i]]);
            }
            if (UseDeadlockHandler)
            {
                _deadlockHandler = new DeadlockHandler(graph, seed);
            }
        }
Example #19
0
    void Start()
    {
        //set up
        //tableSize = 20;
        gridClass = new Grid();
        gridClass.CreateGrid();
        pathFindAlg = new SilverPathfinding(gridClass, tableSize);
        rT          = new ReservationTable(gridClass, tableSize);
        rT.FirstSet();
        agents   = new List <Agent>();
        children = new Dictionary <Transform, Vector3> ();
        foreach (Transform child in transform)
        {
            Agent temp = new Agent(child);
            temp.SetTarget(child.GetComponent <StudentBehaviour>().targetPostion);
            agents.Add(temp);
        }
        oldChildCount = transform.childCount;

        currentMove  = 0;
        stepRate     = 0.1f;
        nextStepTime = 0f;
    }
Example #20
0
        /// <summary>
        /// Gets the reservations and path.
        /// </summary>
        /// <param name="startTime">The start time.</param>
        /// <param name="path">The path.</param>
        /// <param name="reservations">The reservations.</param>
        public void getReservationsAndPath(double startTime, ref Path path, out List <ReservationTable.Interval> reservations)
        {
            //helper for calculation
            var intervallBuilderHelper = new ReservationTable(_graph);

            //output variables
            reservations = new List <ReservationTable.Interval>();

            //get the sequence of edges from the start to the goal node
            var edgesPath   = new List <Edge>();
            var currentNode = GoalNode;

            while (_backpointerEdge[currentNode] != null)
            {
                edgesPath.Add(_backpointerEdge[currentNode]);
                currentNode = _backpointerEdge[currentNode].From;
            }
            edgesPath.Reverse(); //the path was created backwards, so we have to turn it know

            //to from the start to the end and create the intervals
            var currentTime  = startTime;
            var currentAngle = _startAngle;

            for (int edgeNo = 0; edgeNo < edgesPath.Count;)
            {
                var checkPointNodes     = new List <int>();
                var checkPointDistances = new List <double>();

                //start node for hop
                checkPointNodes.Add(edgesPath[edgeNo].From);
                checkPointDistances.Add(0);

                //skip to an edge that points in a different direction
                var currentDistance = 0.0;
                while (edgeNo < edgesPath.Count && edgesPath[edgeNo].Angle == currentAngle)
                {
                    currentDistance += edgesPath[edgeNo].Distance;
                    checkPointNodes.Add(edgesPath[edgeNo].To);
                    checkPointDistances.Add(currentDistance);
                    edgeNo++;
                }

                //add checkpoint node to the past. Leave the last one out, because the check point nodes overlap in
                //every iteration. Example:
                // 1. Iteration: 1 - 2 - 3 (turn)
                // 2. Iteration:         3 - 4 - 5 (turn) ...
                for (int i = 0; i < checkPointNodes.Count - 1; i++)
                {
                    path.AddLast(checkPointNodes[i], (i == 0), 0.0);
                }

                //add reservations for driving among the nodes
                if (checkPointNodes.Count > 1)
                {
                    //add reservations
                    List <double> checkPointTimes = null;
                    _physics.getTimeNeededToMove(0.0, currentTime, currentDistance, checkPointDistances, out checkPointTimes);
                    reservations.AddRange(intervallBuilderHelper.CreateIntervals(checkPointTimes[0], checkPointNodes, checkPointTimes, false));

                    //move time forward
                    currentTime = checkPointTimes[checkPointTimes.Count - 1];
                }

                //add reservation for turning ahead the next node
                if (edgeNo < edgesPath.Count)
                {
                    var timeNeededToTurn = _physics.getTimeNeededToTurn(Graph.DegreeToRad(currentAngle), Graph.DegreeToRad(edgesPath[edgeNo].Angle));
                    currentAngle = edgesPath[edgeNo].Angle;

                    //create reservation for turn
                    reservations.Add(new ReservationTable.Interval(edgesPath[edgeNo].From, currentTime, currentTime + timeNeededToTurn));
                    currentTime += timeNeededToTurn;
                }
            }

            //add destination
            path.AddLast(GoalNode, true, 0.0);
        }
Example #21
0
 private void POST_Confirm_Reservation()
 {
     ReservationTable.UpdateReservationStatus(long.Parse(Request.Form["ResID"]), ReservationStatus.ACCEPTED);
     NotificationTable.CreateNotification(UserAgent.Account.Id, long.Parse(Request.Form["CustomerID"]), long.Parse(Request.Form["ResID"]), 1);
 }
Example #22
0
 private void POST_Decline_Reservation()
 {
     ReservationTable.UpdateReservationStatus(long.Parse(Request.Form["ResID"]), ReservationStatus.DECLINED);
     NotificationTable.CreateNotification(UserAgent.Account.Id, long.Parse(Request.Form["CustomerIDCancel"]), long.Parse(Request.Form["ResIDCancel"]), 0);
 }
Example #23
0
        /// <summary>
        /// Find the path for all the agents.
        /// </summary>
        /// <param name="currentTime">The current Time.</param>
        /// <param name="agents">agents</param>
        /// <param name="obstacleNodes">The way points of the obstacles.</param>
        /// <param name="lockedNodes"></param>
        /// <param name="nextReoptimization">The next re-optimization time.</param>
        /// <param name="communicator">The communicator used for communication with the corresponding instance.</param>
        public void FindPaths(double currentTime, List <Agent> agents, double runtimeLimit, PathPlanningCommunicator communicator)
        {
            if (agents.Count == 0)
            {
                return;
            }

            var stopwatch = new Stopwatch();

            stopwatch.Restart();

            //0: init low level solver
            LowLevSolver.Init(currentTime, agents);

            //1: assign each agent to a singleton group
            var agentGroups        = new Dictionary <int, List <Agent> >(agents.ToDictionary(a => a.ID, a => new List <Agent>(new Agent[] { a })));
            var groundIdAssigments = new Dictionary <int, int>(agents.ToDictionary(a => a.ID, a => a.ID));

            //2: plan a path for each group
            var plannedPath = new Dictionary <int, List <PlannedPath> >(agentGroups.ToDictionary(ag => ag.Key, ag => LowLevSolver.FindPaths(ag.Value)));

            var reservationTable = new ReservationTable(_graph, true, true, false);

            //set fixed blockage
            var fixedBlockage = AgentInfoExtractor.getStartBlockage(agents, currentTime);

            foreach (var agent in fixedBlockage.Keys)
            {
                foreach (var interval in fixedBlockage[agent])
                {
                    reservationTable.Add(interval, agent.ID);
                }
            }

            //3: repeat
            while (agentGroups.Count > 1)
            {
                reservationTable.Clear();

                //4: simulate execution of all paths until a conflict occurs
                int conflictAgent1 = -1;
                int conflictGroup1 = -1;
                int conflictAgent2 = -1;
                int conflictGroup2 = -1;
                int conflictNode;
                var foundConflict = false;
                foreach (var groupId in agentGroups.Keys)
                {
                    for (var agentIndex = 0; agentIndex < agentGroups[groupId].Count && !foundConflict; agentIndex++)
                    {
                        foundConflict = !reservationTable.IntersectionFree(plannedPath[groupId][agentIndex].Reservations, out conflictNode, out conflictAgent1);
                        if (foundConflict)
                        {
                            //remember the conflict agent
                            conflictAgent2 = plannedPath[groupId][agentIndex].Agent.ID;
                            conflictGroup2 = groupId;
                            conflictGroup1 = groundIdAssigments[conflictAgent1];

                            if (conflictGroup1 == conflictGroup2)
                            {
                                foundConflict = false;
                            }
                        }
                        else
                        {
                            //just add intervals
                            reservationTable.Add(plannedPath[groupId][agentIndex].Reservations, plannedPath[groupId][agentIndex].Agent.ID);
                        }
                    }
                }


                if (stopwatch.ElapsedMilliseconds / 1000.0 > runtimeLimit * 0.9)
                {
                    communicator.SignalTimeout();
                    break;
                }

                if (foundConflict)
                {
                    //5: merge two conflicting groups into a single group
                    //merge
                    agentGroups[conflictGroup1].AddRange(agentGroups[conflictGroup2]);
                    //delete old group
                    agentGroups.Remove(conflictGroup2);
                    plannedPath.Remove(conflictGroup2);
                    //reset Assignment
                    for (int agentIndex = 0; agentIndex < agentGroups[conflictGroup1].Count; agentIndex++)
                    {
                        groundIdAssigments[agentGroups[conflictGroup1][agentIndex].ID] = conflictGroup1;
                    }

                    //6: cooperatively plan new group
                    plannedPath[conflictGroup1] = LowLevSolver.FindPaths(agentGroups[conflictGroup1]);
                }
                else
                {
                    //7: until no conflicts occur
                    break;
                }
            }

            //8: solution ← paths of all groups combined
            foreach (var groupId in agentGroups.Keys)
            {
                for (var agentIndex = 0; agentIndex < agentGroups[groupId].Count; agentIndex++)
                {
                    agentGroups[groupId][agentIndex].Path = plannedPath[groupId][agentIndex].Path;//9: return solution
                    if (agentGroups[groupId][agentIndex].Path.Count <= 1)
                    {
                        _deadlockHandler.RandomHop(agentGroups[groupId][agentIndex]);
                    }
                }
            }
        }
Example #24
0
 /// <summary>
 /// Constructs a new instance
 /// </summary>
 /// <param name="owner">superordinate statistics object</param>
 /// <param name="fu">hardware functional unit instance</param>
 /// <param name="reservation">reservation table</param>
 internal FUStatistics(AllocationStatistics owner, Component fu, ReservationTable reservation)
 {
     Owner       = owner;
     FU          = fu;
     Reservation = reservation;
 }
Example #25
0
        /// <summary>
        /// Generates the wait node.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <returns></returns>
        public Tuple <int, List <ReservationTable.Interval>, List <Collision> > GenerateWaitNode(int parent, ReservationTable reservationTable)
        {
            List <Collision> collisions;

            reservationTable.IntersectionFree(NodeTo2D(parent), NodeTime[parent], NodeTime[parent] + _lengthOfAWaitStep, out collisions);

            //add successor
            var waitNode = Tuple.Create(_numNodeId, new List <ReservationTable.Interval>(new[] { new ReservationTable.Interval(NodeTo2D(parent), NodeTime[parent], NodeTime[parent] + _lengthOfAWaitStep) }), collisions);

            NodeTime.Add(NodeTime[parent] + _lengthOfAWaitStep);
            NodeBackpointerId.Add(parent);
            NodeBackpointerLastStopId.Add(_numNodeId);
            NodeBackpointerEdge.Add(null);
            _numNodeId++;
            return(waitNode);
        }
Example #26
0
        /// <summary>
        /// Gets the actions.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns>actions</returns>
        public List <Tuple <int, List <ReservationTable.Interval>, List <Collision> > > GetActions(int n, int prio, ReservationTable reservationTable)
        {
            var successors = new List <Tuple <int, List <ReservationTable.Interval>, List <Collision> > >();

            List <int>       checkPointNodes     = new List <int>();
            List <double>    checkPointDistances = new List <double>();
            List <double>    checkPointTimes;
            List <Collision> collisions;

            //wait successor
            reservationTable.IntersectionFree(NodeTo2D(n), NodeTime[n], NodeTime[n] + _lengthOfAWaitStep, out collisions);
            if (collisions == null || collisions.All(c => c.priority < prio || c.agentId == _agent.ID))
            {
                //add successor
                successors.Add(Tuple.Create(_numNodeId, new List <ReservationTable.Interval>(new[] { new ReservationTable.Interval(NodeTo2D(n), NodeTime[n], NodeTime[n] + _lengthOfAWaitStep) }), collisions));
                NodeTime.Add(NodeTime[n] + _lengthOfAWaitStep);
                NodeBackpointerId.Add(n);
                NodeBackpointerLastStopId.Add(_numNodeId);
                NodeBackpointerEdge.Add(null);
                _numNodeId++;
            }

            //current angle
            short lastStopAngleAfterTurn = GetLastStopAngleAfterTurn(n);

            //for each direction
            foreach (var direction in _graph.Edges[NodeTo2D(n)])
            {
                //clear temporary data structures
                NodeTimeTemp.Clear();
                NodeBackpointerIdTemp.Clear();
                NodeBackpointerLastTurnIdTemp.Clear();
                NodeBackpointerEdgeTemp.Clear();

                //initiate checkpoints
                checkPointTimes = null;
                checkPointNodes.Clear();
                checkPointDistances.Clear();

                //Our aim is to calculate the distance for a hop.
                //A hop is defined as follows: The longest distance between two nodes, where no turn is necessary.
                //The end of the hop is "node". In this method we search for the start ("lastTurnNode") and calculate the g as follows:
                //g(node) = time needed to get to "lastTurnNode" + time needed to turn + time needed to get to node

                //angle i had before my current angle: lastTurnAngle
                //my current angle: thisAngle
                //the angle i want to go to: direction.Angle
                int lastStopId = NodeBackpointerLastStopId[n];

                if (direction.Angle != lastStopAngleAfterTurn)
                {
                    //we turn at n
                    lastStopId = n;
                    checkPointDistances.Add(0.0);
                    checkPointNodes.Add(NodeTo2D(n));
                }
                else
                {
                    //get the intermediate checkpoints
                    AddCheckPointDistances(lastStopId, n, checkPointNodes, checkPointDistances);
                }

                //time needed to get to the target orientation
                //last stop angle after turn of the last stop <=> last stop angle before turn
                short  lastStopAngleBeforeTurn = GetLastStopAngleAfterTurn(lastStopId);
                double timeToTurn = _agent.Physics.getTimeNeededToTurn(Graph.DegreeToRad(lastStopAngleBeforeTurn), Graph.DegreeToRad(direction.Angle));

                //check if there is enough free time to rotate in the direction

                /*
                 * if (timeToTurn > 0)
                 * {
                 *  reservationTable.IntersectionFree(NodeTo2D(lastStopId), NodeTime[lastStopId], NodeTime[lastStopId] + timeToTurn, out collisions);
                 *  if (collisions != null && collisions.All(c => c.priority >= prio && c.agentId != _agent.ID))
                 *      continue;
                 * }
                 *
                 * => Do it later
                 *
                 */

                //generate successors
                var currentNode     = NodeTo2D(n);
                var agentAngle      = direction.Angle;
                var backpointerNode = n;

                //get drive distance
                var driveDistance = checkPointDistances[checkPointDistances.Count - 1];

                var foundNext = true;
                var pathFree  = false;
                //try to find the first node in this direction, which path is free
                while (foundNext && !pathFree)
                {
                    foundNext = false;

                    //search for next edges in same direction
                    foreach (var edge in _graph.Edges[currentNode])
                    {
                        if (Math.Abs(edge.Angle - agentAngle) < 2)
                        {
                            //skip blocked edges
                            if (edge.ToNodeInfo.IsLocked || (!_agent.CanGoThroughObstacles && edge.ToNodeInfo.IsObstacle))
                            {
                                //blocked
                                foundNext = false;
                                break;
                            }

                            //cumulate
                            driveDistance += edge.Distance;

                            //add checkpoint
                            checkPointDistances.Add(driveDistance);
                            checkPointNodes.Add(edge.To);

                            //check whether it is intersection free
                            var timeToMove = _agent.Physics.getTimeNeededToMove(0f, NodeTime[lastStopId] + timeToTurn, driveDistance, checkPointDistances, out checkPointTimes);

                            //add time needed to turn
                            if (checkPointTimes.Count > 0)
                            {
                                checkPointTimes[0] -= timeToTurn;
                            }

                            //check if driving action is collision free
                            reservationTable.IntersectionFree(checkPointNodes, checkPointTimes, false, out collisions);
                            pathFree = collisions == null || collisions.All(c => c.priority < prio || c.agentId == _agent.ID);

                            //add node to temp => will be added, if a valid successor will be found
                            NodeTimeTemp.Add(NodeTime[lastStopId] + timeToTurn + timeToMove);
                            NodeBackpointerIdTemp.Add(backpointerNode);
                            NodeBackpointerLastTurnIdTemp.Add(lastStopId);
                            NodeBackpointerEdgeTemp.Add(edge);

                            if (pathFree)
                            {
                                //treat only the last one as successor
                                successors.Add(Tuple.Create(_numNodeId + NodeTimeTemp.Count - 1, reservationTable.CreateIntervals(NodeTime[lastStopId], checkPointNodes, checkPointTimes, false), collisions));
                                _numNodeId += NodeTimeTemp.Count;

                                //add temporary successors
                                NodeTime.AddRange(NodeTimeTemp);
                                NodeBackpointerId.AddRange(NodeBackpointerIdTemp);
                                NodeBackpointerLastStopId.AddRange(NodeBackpointerLastTurnIdTemp);
                                NodeBackpointerEdge.AddRange(NodeBackpointerEdgeTemp);
                            }

                            backpointerNode = _numNodeId + NodeTimeTemp.Count - 1;
                            currentNode     = edge.To;
                            foundNext       = true;
                            break;
                        }
                    }
                }
            }

            return(successors);
        }
Example #27
0
 private void POST_Delete_Reservation()
 {
     ReservationTable.DeleteReservation(long.Parse(Request.Form["ResID"]));
 }
Example #28
0
        public async Task AddReservation(ReservationTable reservation)
        {
            await _context.ReservationTables.AddAsync(reservation);

            await _context.SaveChangesAsync();
        }
Example #29
0
 public AStar(ReservationTable rTable, Grid grid)
 {
     this.rTable = rTable;
     this.grid   = grid;
 }
Example #30
0
    void Awake()
    {
        rTable = new ReservationTable();

        //MapLoader mapLoader = new MapLoader (new Vector2(20, 20), 0.5f);
        //mapData = mapLoader.LoadMap ("A", "startPos", "endPos");
        if (map == 1)
        {
            mapLoader = new MapLoader(new Vector2(11, 11), 0.5f);
            mapData   = mapLoader.LoadMap("discObst1/discObst1",
                                          "discObst1/discObst1StartPos",
                                          "discObst1/discObst1GoalPos",
                                          "discObst1/discObst1CustomerPos");
        }
        if (map == 2)
        {
            mapLoader = new MapLoader(new Vector2(20, 20), 0.5f);
            mapData   = mapLoader.LoadMap("discObst2/discObst2",
                                          "discObst2/discObst2StartPos",
                                          "discObst2/discObst2GoalPos",
                                          "discObst2/discObst2CustomerPos");
        }

        if (map == 3)
        {
            mapLoader = new MapLoader(new Vector2(11, 11), 0.5f);
            mapData   = mapLoader.LoadMap("discObst1/exam/discObst1",
                                          "discObst1/exam/discObst1StartPos",
                                          "discObst1/exam/discObst1GoalPos",
                                          "discObst1/exam/discObst1CustomerPos");
        }

        if (map == 4)
        {
            mapLoader = new MapLoader(new Vector2(20, 20), 0.5f);
            mapData   = mapLoader.LoadMap("discObst2/exam/discObst2",
                                          "discObst2/exam/discObst2StartPos",
                                          "discObst2/exam/discObst2GoalPos",
                                          "discObst2/exam/discObst2CustomerPos");
        }

        nodeDiameter  = mapData.nodeRadius * 2;
        gridWorldSize = mapData.gridWorldSize;
        // #nodes that can fit into the x-space
        gridSizeX = Mathf.RoundToInt(gridWorldSize.x / nodeDiameter);
        gridSizeY = Mathf.RoundToInt(gridWorldSize.y / nodeDiameter);
        CreateGrid();

        for (int i = 0; i < gridSizeX; i++)
        {
            for (int j = 0; j < gridSizeY; j++)
            {
                if (neighbourhood == 4)
                {
                    FillNeighbourhood4(grid[i, j]);
                }
            }
        }
        foreach (Node node in grid)
        {
        }
    }