Beispiel #1
0
        void DFS(int baseLineID)
        {
            //foreach (CarStallMeta carMeta in CarStallMeta.META_LIST)

            CarStallRow c = new CarStallRow(
                baseLineID,
                zone.edges[baseLineID],
                CarStallMeta.NINETY_DEGREE,
                zone);
            // RoadRow r = new RoadRow(baseLineID,  zone.edges[baseLineID], RoadMeta.NORMAL_ROAD);

            // create new result and metric
            RowSolverResult branchC = (RowSolverResult)this.SOLVER_RESULT_FACTORY.CreateNew();
            // RowSolverResult branchR = (RowSolverResult) this.SOLVER_RESULT_FACTORY.CreateNew();
            Metric mC = this.METRIC_FACTORY.CreateNew();

            // Metric mR = this.METRIC_FACTORY.CreateNew();
            SetMetricAndResult(mC, branchC);
            // SetMetricAndResult(mR, branchR);


            RowNode startC = GrowNode(null, c, branchC);

            // RowNode startR = GrowNode(null, r, branchR);
            //  RowNode startC = c;
            // RowNode startR = r;
            branchC.Add(startC);
            //  branchR.Add(startR);

            Grow(startC, branchC, baseLineID);
            // Grow(startR, branchR, baseLineID);
        }
Beispiel #2
0
        public RowSolverResult Clone()
        {
            RowSolverResult res = new RowSolverResult();

            res.totalWidth   = this.totalWidth;
            res.endNode      = this.endNode;
            res.singleRowNum = this.singleRowNum;
            return(res);
        }
Beispiel #3
0
        public new int CompareTo(object obj)
        {
            if (!(obj is RowSolverResult))
            {
                throw new ArgumentException();
            }
            RowSolverResult other = (RowSolverResult)obj;

            return((int)(this.totalStall - other.totalStall));
        }
Beispiel #4
0
        public RowSolverResult GetBest(int n)
        {
            if (n >= resultRepository.Count())
            {
                return(null);
            }


            RowSolverResult res = resultRepository[n];

            //writeLog(res.endNode);
            return(res);
        }
Beispiel #5
0
        RowNode GrowNode(RowNode node, RowNode newNode, RowSolverResult branch)
        {
            Console.WriteLine("GrowNode\n");
            // node is Road && newNode is CarStall
            // For adding connection to newNode
            if (node != null)
            {
                if (node is RoadRow && newNode is CarStallRow)
                {
                    newNode = (CarStallRow)newNode;
                    // newNode.AddConnection();
                }
            }
            newNode.prev = node;

            // add new Node
            branch.Add(newNode);

            return(newNode);
        }
Beispiel #6
0
        void Grow(RowNode node, RowSolverResult branch, int baseLineID)
        {
            // Cut Branch
            if (branch.singleRowNum < 0)
            {
                return;
            }

            // reach end.. base case
            if (branch.totalWidth > zone.maxOffsetLength[baseLineID])
            {
                branch.StepBack();
                resultRepository.Add(branch);
                return;
            }

            // recursive
            // add RoadRow
            if (node != null && node is CarStallRow)
            {
                RoadRow r = new RoadRow(
                    baseLineID,
                    zone.OffsetInZone(node.referenceLine, baseLineID, node.GetClearHeight()),
                    RoadMeta.NORMAL_ROAD,
                    zone
                    );

                RowSolverResult newBranch = branch.Clone();
                RowNode         newNode   = GrowNode(node, r, newBranch);
                Grow(newNode, newBranch, baseLineID);
            }
            // add CarRow
            else
            {
                foreach (CarStallMeta carMeta in CarStallMeta.META_LIST)
                {
                    CarStallRow c = new CarStallRow(
                        baseLineID,
                        zone.OffsetInZone(node.referenceLine, baseLineID, node.GetClearHeight()),
                        carMeta,
                        zone
                        );
                    // Grow a Car Branch
                    RowSolverResult carBranch = branch.Clone();
                    RowNode         carNode   = GrowNode(node, c, carBranch);
                    Grow(carNode, carBranch, baseLineID);
                }
            }



            /* OLD IMPLEMENTATION
             * foreach (CarStallMeta carMeta in CarStallMeta.META_LIST)
             * {
             *
             *  // If exceed the maxWidth(base case)
             *  if (branch.totalWidth + carMeta.GetClearHeight() >= zone.maxOffsetLength[baseLineID])
             *  {
             *      resultRepository.Add(branch);
             *      continue;
             *      if (!IsLegalAddition(node))
             *      {
             *          continue;
             *      }
             *      else
             *      {
             *          resultRepository.Add(branch);
             *
             *          if (resultRepository.Count >= BEST_RESULT_NUMBER)
             *          {
             *              resultRepository.Remove(resultRepository.Min);
             *          }
             *
             *          continue;
             *      }
             *  }
             *
             *  // recursive case
             *  // if node.referenceLine is None:
             *  // self.resultRepository.append(branch)
             *  // return
             *
             *
             *  // if this node is CarStall
             *  if (node is CarStallRow)
             *  {
             *      // not connected to Road
             *      if (!node.IsConnectedToRoadRow())
             *      {
             *          RoadRow r = new RoadRow(
             *              baseLineID,
             *              zone.OffsetInZone(node.referenceLine, baseLineID, node.GetClearHeight()),
             *              RoadMeta.NORMAL_ROAD
             *              );
             *
             *          RowSolverResult newBranch = Copy.DeepClone(branch);
             *          RowNode newNode = GrowNode(node, r, newBranch);
             *          Grow(newNode, newBranch, baseLineID);
             *      }
             *      // if connected to Road
             *      else
             *      {
             *          CarStallRow c = new CarStallRow(
             *                  baseLineID,
             *                  zone.OffsetInZone(node.referenceLine, baseLineID, node.GetClearHeight()),
             *                  carMeta
             *                  );
             *
             *          RoadRow r = new RoadRow(
             *                  baseLineID,
             *                  zone.OffsetInZone(node.referenceLine, baseLineID, node.GetClearHeight()),
             *                  RoadMeta.NORMAL_ROAD
             *                  );
             *
             *          // Grow a Car Branch
             *          RowSolverResult carBranch = Copy.DeepClone(branch);
             *          RowNode carNode = GrowNode(node, c, carBranch);
             *          Grow(carNode, carBranch, baseLineID);
             *
             *          // Grow a Road Branch
             *          RowSolverResult roadBranch = Copy.DeepClone(branch);
             *          RowNode roadNode = GrowNode(node, c, roadBranch);
             *          Grow(roadNode, roadBranch, baseLineID);
             *      }
             *  }
             *  // if this node is a Road
             *  else if (node is RoadRow)
             *  {
             *      CarStallRow c = new CarStallRow(
             *                  baseLineID,
             *                  zone.OffsetInZone(node.referenceLine, baseLineID, node.GetClearHeight()),
             *                  carMeta
             *                  );
             *      RowSolverResult newBranch = Copy.DeepClone(branch);
             *      RowNode newNode = GrowNode(node, c, newBranch);
             *      Grow(newNode, newBranch, baseLineID);
             *
             *  }
             * }
             */
        }
Beispiel #7
0
 public RowSolver(Metric metric, RowSolverResult RowSolverResult) : base(metric, RowSolverResult)
 {
     resultRepository = new List <RowSolverResult>();
 }