Ejemplo n.º 1
0
    public PrepareMeatMethod1()
    {
        SubTasks.Add(ExampleDomain.Instance.GetTask(DefinedTaskEnum.EatMeatTask));
        SubTasks.Add(ExampleDomain.Instance.GetTask(DefinedTaskEnum.MoveToTask));

        PreConditions.Add(ExampleDomain.Instance.GetPreCondition(DefinedPreConditionEnum.EatMeatPreCondition));
    }
Ejemplo n.º 2
0
        public JsonResult ApiCreateSubTask(int taskID, string name, string description)
        {
            SubTasks subTask = new SubTasks();

            subTask.Name        = name;
            subTask.Description = description;
            subTask.Status      = _context.taskStatuses.First(s => s.Name == "Incomplete");


            var project = _context.projects.Where(p => p.Tasks.First(t => t.ID == taskID).ID == taskID).Include(pt => pt.Tasks).ThenInclude(pt => pt.SubTasks);

            //Add the newly created projTask to the database
            _context.subTasks.Add(subTask);

            //Add the projTask to the project within the database
            project.First().Tasks.First(st => st.ID == taskID).SubTasks.Add(subTask);

            _context.SaveChanges();

            var data = new
            {
                stID = subTask.ID
            };


            return(Json(data));
        }
Ejemplo n.º 3
0
        public static List <SubTasks> getSubTasks(int taskId)
        {
            List <SubTasks> subTasks = new List <SubTasks>();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                string     query = @"Select Id,SubTaskName,SubTaskDescription,SubTaskDate,TaskId from SubTasks where TaskId =  @taskId";
                SqlCommand cmd   = new SqlCommand(query, con);
                cmd.Parameters.AddWithValue("@taskId", taskId);
                con.Open();
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        SubTasks subtaski = new SubTasks();
                        subtaski.Id                 = Convert.ToInt32(reader["Id"]);
                        subtaski.SubTaskName        = reader["SubTaskName"].ToString();
                        subtaski.SubTaskDescription = reader["SubTaskDescription"].ToString();
                        subtaski.SubTaskDate        = Convert.ToDateTime(reader["SubTaskDate"]);
                        subtaski.TaskId             = Convert.ToInt32(reader["TaskId"]);
                        subTasks.Add(subtaski);
                    }
                }

                con.Close();
            }
            return(subTasks);
        }
Ejemplo n.º 4
0
        public Task AddSubTask(Task task)
        {
            task.ParentId = Id;
            SubTasks.Add(task);

            return(this);
        }
Ejemplo n.º 5
0
        public Task UpdateSubTask(Task task)
        {
            SubTasks.Remove(task);

            task.ParentId = Id;
            SubTasks.Add(task);

            return(this);
        }
Ejemplo n.º 6
0
    public static void Main(string[] args)
    {
        Tasks    tasks    = new Tasks();
        SubTasks subTasks = new SubTasks(tasks);

        while (true)
        {
            Thread.Sleep(1000);
            tasks.Warn();
        }
    }
Ejemplo n.º 7
0
    public static void Main(string[] args)
    {
        Tasks    tasks = new Tasks();
        SubTasks s     = new SubTasks(tasks);

        int i = 20;

        while (i-- >= 0)
        {
            tasks.Warn();
            Thread.Sleep(1000);
        }
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the tasks statistics.
        /// </summary>
        /// <param name="tasks">The tasks.</param>
        public void GetTasksStatistics(List <TaskStatistics> tasks)
        {
            if (!_isStarted)
            {
                return;
            }
            var thisTask = new TaskStatistics
            {
                TaskName    = Name,
                FinishedAt  = EndTime,
                ElapsedTime = ElapsedTime.TotalMinutes
            };

            tasks.Add(thisTask);

            SubTasks.ForEach(item => item.GetTasksStatistics(tasks));
        }
Ejemplo n.º 9
0
 public static bool AddSubTask(SubTasks subTask)
 {
     using (SqlConnection con = new SqlConnection(connectionString))
     {
         subTask.SubTaskDate = DateTime.Now;
         string     query = @"Insert into SubTasks(SubTaskName,SubTaskDescription,SubTaskDate,TaskId) values (@subtaskName,@subtaskDescription,@subtaskDate,@taskId)";
         SqlCommand cmd   = new SqlCommand(query, con);
         cmd.Parameters.AddWithValue("@subtaskName", subTask.SubTaskName);
         cmd.Parameters.AddWithValue("@subtaskDescription", subTask.SubTaskDescription);
         cmd.Parameters.AddWithValue("@subtaskDate", subTask.SubTaskDate);
         cmd.Parameters.AddWithValue("@taskId", subTask.TaskId);
         con.Open();
         cmd.ExecuteNonQuery();
         con.Close();
     }
     return(true);
 }
Ejemplo n.º 10
0
    public static void Main()
    {
        Task t1 = new Task("Wash the dishes", System.DateTime.Today);
        Task t2 = new Task("Do my homework", System.DateTime.Today);
        Task t3 = new Task("Clean my bedroom", System.DateTime.Today);

        Tasks tasks = new Tasks(t1, t2, t3);

        SubTasks subTasts = new SubTasks(tasks);

        System.Threading.Tasks.Task task1 = System.Threading.Tasks.Task.Run(() => tasks.warn(new TaskEventArgs(t1.Description, t1.DueDate - System.DateTime.Today)));
        System.Threading.Tasks.Task task2 = System.Threading.Tasks.Task.Run(() => tasks.warn(new TaskEventArgs(t2.Description, t2.DueDate - System.DateTime.Today)));
        System.Threading.Tasks.Task task3 = System.Threading.Tasks.Task.Run(() => tasks.warn(new TaskEventArgs(t3.Description, t3.DueDate - System.DateTime.Today)));

        //task1.Wait(1000);
        task2.Wait(1000);
        task3.Wait(1000);
    }
Ejemplo n.º 11
0
        /// <summary>
        /// Serializes this instance.
        /// </summary>
        public virtual void Serialize()
        {
            if (!_isStarted)
            {
                return;
            }

            TimeSpan elapsed = EndTime.Subtract(StartTime);

            Logger.Info(".......................................");
            Logger.Info(string.Format("{0,-18} : {1}", "Task Name", Name));
            if (!ShowOnlyElapsedTime)
            {
                Logger.Info(string.Format("{0,-18} : {1}", "Start Time", StartTime.ToLongTimeString()));
                Logger.Info(string.Format("{0,-18} : {1}", "End Time", EndTime.ToLongTimeString()));
            }
            Logger.Info(string.Format("{0,-18} : {1} ms", "Elapsed Time", elapsed.TotalMilliseconds));

            Fields.ForEach(item =>
            {
                if (null != item)
                {
                    Logger.Info(string.Format("{0,-18} : {1}", item.Name, item.Value));
                }
            }
                           );

            SerializeMessages();

            if (SyncLogger.EnableReportLog)
            {
                // Serialize the logs for Test Reports
                string reportLog = string.Format("{0,-40} | {1,-12} | {2,-12} | {3,-12}", Name,
                                                 StartTime.ToLongTimeString(),
                                                 EndTime.ToLongTimeString(),
                                                 elapsed.TotalMilliseconds);
                ReportLog.Dump(reportLog);
            }

            SubTasks.ForEach(item => item.Serialize());
        }
Ejemplo n.º 12
0
 public bool IsValid()
 {
     return(!string.IsNullOrEmpty(Name) &&
            !string.IsNullOrEmpty(Title) &&
            !string.IsNullOrEmpty(Description) &&
            Uri.IsWellFormedUriString(Url.ToString(), UriKind.RelativeOrAbsolute) &&
            Uri.IsWellFormedUriString(ParentStoryUrl.ToString(), UriKind.RelativeOrAbsolute) &&
            KeyIdentifiers != null &&
            KeyIdentifiers.Any() ? KeyIdentifiers.All(s => s.IsValid()) : true &&
            TestCases != null &&
            TestCases.Any() ? TestCases.All(s => s.IsValid()) : true &&
            Checkups != null &&
            Checkups.Any() ? Checkups.All(s => s.IsValid()) : true &&
            Attachments != null &&
            Attachments.Any() ? Attachments.All(s => Uri.IsWellFormedUriString(s.Value, UriKind.RelativeOrAbsolute)) : true &&
            Queries != null &&
            Queries.Any() ? Queries.All(s => Uri.IsWellFormedUriString(s.Value, UriKind.RelativeOrAbsolute)) : true &&
            Scripts != null &&
            Scripts.Any() ? Scripts.All(s => Uri.IsWellFormedUriString(s.Value, UriKind.RelativeOrAbsolute)) : true &&
            SubTasks.Any() ? SubTasks.All(s => s.IsValid()) : true);
 }
Ejemplo n.º 13
0
        public TaskController()
        {
            User andrea = new User()
            {
                FirstName       = "Andrea",
                LastName        = "Markovski",
                Age             = 35,
                AverageFreeTime = 10,
            };

            Tasks task_01 = new Tasks()
            {
                Title       = "Homework01",
                Description = "MVC",
                Priority    = Priority.Important,
                Status      = Status.NotDone,
                Type        = Type.Work,
            };

            SubTasks subtask_01 = new SubTasks()
            {
                Title       = "SubTask01",
                Description = "SubTask01-Description",
                Status      = Status.NotDone,
            };

            SubTasks subtask_02 = new SubTasks()
            {
                Title       = "SubTask02",
                Description = "SubTask02-Description",
                Status      = Status.NotDone,
            };

            task_01.SubTasks.Add(subtask_01);
            task_01.SubTasks.Add(subtask_02);

            _Andrea = andrea;
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Update the Status of a Task when one of its Substaks changes its Status
 /// When a task is Semi-done, will put a minus sign on its CheckBox
 /// EDIT: Will use the default windows style that puts a little box in the checkbox
 /// </summary>
 private void UpdateTaskStatus()
 {
     //If at least one subtask is Done, then the task is semidone
     if (SubTasks.Any(task => task.Status == TaskStatus.Done) && SubTasks.Any(task => task.Status != TaskStatus.Done))
     {
         this.Status = TaskStatus.SemiDone;
     }
     else
     {
         if (SubTasks.All(task => task.Status == TaskStatus.Done))
         {
             this.Status = TaskStatus.Done;
         }
         ;
         if (SubTasks.All(task => task.Status == TaskStatus.NotDone))
         {
             this.Status = TaskStatus.NotDone;
         }
         if (SubTasks.All(task => task.Status == TaskStatus.SemiDone))
         {
             this.Status = TaskStatus.SemiDone;
         }
     }
 }
Ejemplo n.º 15
0
 public bool RemoveSubTask(ToDoTask task)
 {
     return(SubTasks.Remove(task));
 }
Ejemplo n.º 16
0
 public void AddSubTask(string taskName, string description, DateTimeOffset targetCompletion)
 {
     SubTasks.Add(new ToDoTask(taskName, description, targetCompletion, TaskId));
 }
Ejemplo n.º 17
0
		private void DeleteSubTask(SubTask obj)
		{
			SubTasks.Remove(obj);
			subTaskRepository.Delete(obj.Id);
		}
Ejemplo n.º 18
0
 public void AddSubTask(Issue issue)
 {
     SubTasks.Add(new JIssue(issue));
 }
Ejemplo n.º 19
0
 public void AddSubTask(JIssue issue)
 {
     SubTasks.Add(issue);
 }
Ejemplo n.º 20
0
        public override void Work()
        {
            //获取求解设置
            decimal terminalFactor = _ctx.GetParameter("TerminalFactor", 0.001m);
            int     iteration      = _ctx.GetParameter("Iteration", 10);
            int     resolution     = _ctx.GetParameter("Resolution", 60);
            decimal initMultipler  = _ctx.GetParameter("InitMultiper", 0.1m);

            string objectiveType = _ctx.GetParameter("ObjectiveType", "");

            // 相对-绝对时间转化器
            DiscreteTimeAdapter adapter
                = new DiscreteTimeAdapter(_ctx.StartTime, _ctx.EndTime, resolution);

            // 路径集
            Dictionary <CustomerArrival, List <TravelPath> > pathDict
                = new Dictionary <CustomerArrival, List <TravelPath> >();

            #region 建立初始网络,搜索可行路径
            //目标函数网络
            var objgraph = ObjectNetworkFactory.Create(objectiveType, _ctx, adapter); //new ObjectTravelHyperNetwork(_ctx, adapter);
            objgraph.Build();

            //基础网络
            var basicGraph = new BasicTravelHyperNetwork(_ctx, adapter);
            basicGraph.Build();

            SubTasks.Clear();
            foreach (CustomerArrival customer in _ctx.Pal)
            {
                Task ta = factory.StartNew(() =>
                {
                    var ori   = (_ctx.Wor.Mar[customer.Customer.MarSegID] as IRailwayMarketSegment).OriSta;
                    var des   = (_ctx.Wor.Mar[customer.Customer.MarSegID] as IRailwayMarketSegment).DesSta;
                    var paths = DepthFirstSearcher.FindAllPaths(basicGraph,
                                                                new TravelHyperNode()
                    {
                        Time = adapter.ConvertToDiscreteTime(customer.ArriveTime), Station = ori, Price = 0
                    },
                                                                new TravelHyperNode()
                    {
                        Time = adapter.Horizon + 1440, Station = des, Price = 0
                    });
                    pathDict.Add(customer, new List <TravelPath>());
                    foreach (var path in paths)
                    {
                        pathDict[customer].Add(new TravelPath(basicGraph, path));
                    }
                });
                SubTasks.Add(ta);
            }
            Task.WaitAll(SubTasks.ToArray());
            #endregion

            #region 构建对偶问题 with CPLEX
            Cplex model = new Cplex();
            model.SetOut(null);
            INumVar theta = model.NumVar(double.MinValue, double.MaxValue); //θ

            model.AddMaximize(theta);

            Dictionary <IServiceSegment, INumVar> dual_rho = _ctx.Wor.RailwayTimeTable.Trains
                                                             .SelectMany(i => i.ServiceSegments).ToDictionary(i => i, i =>
                                                                                                              model.NumVar(0, double.MaxValue));

            Dictionary <CustomerArrival, Dictionary <TravelPath, INumVar> > dual_mu =
                new Dictionary <CustomerArrival, Dictionary <TravelPath, INumVar> >();
            foreach (CustomerArrival customer in _ctx.Pal)
            {
                dual_mu.Add(customer, new Dictionary <TravelPath, INumVar>());
                foreach (var path in pathDict[customer])
                {
                    dual_mu[customer].Add(path, model.NumVar(0, double.MaxValue));
                }
            }

            Dictionary <IEdge <TravelHyperNode>, INumVar> dual_lambda =
                new Dictionary <IEdge <TravelHyperNode>, INumVar>();
            foreach (CustomerArrival customer in _ctx.Pal)
            {
                foreach (var path in pathDict[customer])
                {
                    if (!dual_lambda.ContainsKey(path.ReservationArc))
                    {
                        dual_lambda.Add(path.ReservationArc, model.NumVar(0, double.MaxValue));
                    }
                }
            }
            #endregion

            #region 变量与乘子
            //决策变量 x
            Dictionary <CustomerArrival, TravelPath> x
                = new Dictionary <CustomerArrival, TravelPath>();
            foreach (CustomerArrival customer in _ctx.Pal)
            {
                x.Add(customer, new TravelPath());
            }

            //决策变量 w
            Dictionary <ITrainTrip, Dictionary <IRailwayStation, PricePath> > w
                = new Dictionary <ITrainTrip, Dictionary <IRailwayStation, PricePath> >();
            foreach (var train in _ctx.Wor.RailwayTimeTable.Trains)
            {
                w.Add(train, new Dictionary <IRailwayStation, PricePath>());
                foreach (var sta in _ctx.Wor.Net.StationCollection)
                {
                    w[train].Add(sta, null);
                }
            }

            //辅助变量 y
            //记录每条弧在当前w的取值下是否可行(available),值为true = 可行;false = 不可行
            //超出了y记录的reservation arc 不会有人走
            Dictionary <IEdge <TravelHyperNode>, bool> y
                = new Dictionary <IEdge <TravelHyperNode>, bool>();
            foreach (var p in pathDict.Values.SelectMany(i => i))
            {
                if (p.ReservationArc != null && !y.ContainsKey(p.ReservationArc))
                {
                    y.Add(p.ReservationArc, false);
                }
            }

            //拉格朗日乘子 rho
            Dictionary <IServiceSegment, decimal> LM_rho = _ctx.Wor.RailwayTimeTable.Trains
                                                           .SelectMany(i => i.ServiceSegments).ToDictionary(i => i, i => initMultipler);

            //拉格朗日乘子 rho 迭代方向
            Dictionary <IServiceSegment, decimal> Grad_rho = _ctx.Wor.RailwayTimeTable.Trains
                                                             .SelectMany(i => i.ServiceSegments).ToDictionary(i => i, i => initMultipler);


            //拉格朗日乘子 mu
            Dictionary <CustomerArrival, Dictionary <TravelPath, decimal> > LM_mu
                = new Dictionary <CustomerArrival, Dictionary <TravelPath, decimal> >();
            foreach (CustomerArrival customer in _ctx.Pal)
            {
                LM_mu.Add(customer, new Dictionary <TravelPath, decimal>());
                foreach (var path in pathDict[customer])
                {
                    LM_mu[customer].Add(path, initMultipler);
                }
            }
            //拉格朗日乘子 mu 迭代方向
            Dictionary <CustomerArrival, Dictionary <TravelPath, decimal> > Grad_mu
                = new Dictionary <CustomerArrival, Dictionary <TravelPath, decimal> >();
            foreach (CustomerArrival customer in _ctx.Pal)
            {
                Grad_mu.Add(customer, new Dictionary <TravelPath, decimal>());
                foreach (var path in pathDict[customer])
                {
                    Grad_mu[customer].Add(path, initMultipler);
                }
            }

            //拉格朗日乘子 lambda
            Dictionary <IEdge <TravelHyperNode>, decimal> LM_lambda = new Dictionary <IEdge <TravelHyperNode>, decimal>();
            //WARNING: 这里缺少了没有旅客选择的reservation arc
            foreach (CustomerArrival customer in _ctx.Pal)
            {
                foreach (var path in pathDict[customer])
                {
                    if (!LM_lambda.ContainsKey(path.ReservationArc))
                    {
                        LM_lambda.Add(path.ReservationArc, initMultipler);
                    }
                }
            }

            //拉格朗日乘子 lambda 迭代方向
            Dictionary <IEdge <TravelHyperNode>, decimal> Grad_lambda = new Dictionary <IEdge <TravelHyperNode>, decimal>();
            foreach (CustomerArrival customer in _ctx.Pal)
            {
                foreach (var path in pathDict[customer])
                {
                    if (!Grad_lambda.ContainsKey(path.ReservationArc))
                    {
                        Grad_lambda.Add(path.ReservationArc, initMultipler);
                    }
                }
            }

            #endregion

            decimal bigM1      = pathDict.Max(i => i.Value.Max(j => basicGraph.GetPathCost(j)));
            decimal bigM2      = _ctx.Pal.Count();
            decimal bigM       = Math.Max(bigM1, bigM2);
            decimal lowerBound = decimal.MinValue;
            decimal upperBound = decimal.MaxValue;
            bool    flag       = false;//对偶问题有解

            PrintIterationInfo($"Iteration Number, Lower Bound, Upper Bound, Best Lower Bound, Best Upper Bound, Total Gap(%) ");

            for (int iter = 0; iter < iteration; iter++)
            {
                Log($"--------------第{iter}轮求解开始--------------");

                bool hasFeasibleSolution = true;

                #region 求解LR问题
                SubTasks.Clear();
                foreach (CustomerArrival customer in _ctx.Pal)// 求解x
                {
                    Task ta = factory.StartNew(() =>
                    {
                        var graph = new LRxTravelHyperNetwork(_ctx, adapter, objgraph, customer, pathDict, LM_rho, LM_mu, LM_lambda);
                        graph.Build();
                        var ori = (_ctx.Wor.Mar[customer.Customer.MarSegID] as IRailwayMarketSegment).OriSta;
                        var des = (_ctx.Wor.Mar[customer.Customer.MarSegID] as IRailwayMarketSegment).DesSta;
                        DijkstraShortestPaths <DirectedWeightedSparseGraph <TravelHyperNode>, TravelHyperNode> dijkstra
                            = new DijkstraShortestPaths <DirectedWeightedSparseGraph <TravelHyperNode>, TravelHyperNode>(graph, new TravelHyperNode()
                        {
                            Time    = adapter.ConvertToDiscreteTime(customer.ArriveTime),
                            Station = ori,
                            Price   = 0
                        });    //考虑该旅客到达时间
                        x[customer] = new TravelPath(graph, dijkstra.ShortestPathTo(
                                                         new TravelHyperNode()
                        {
                            Time    = adapter.Horizon + 1440,
                            Station = des,
                            Price   = 0
                        }));
                    });
                    SubTasks.Add(ta);
                }
                foreach (var train in _ctx.Wor.RailwayTimeTable.Trains)
                {
                    foreach (IRailwayStation station in _ctx.Wor.Net.StationCollection)// 求解w
                    {
                        Task ta = factory.StartNew(() =>
                        {
                            var graph = DpnAlgorithm.BuildLRwGraph(_ctx, adapter, train, station, pathDict, basicGraph.LinkTrainDict, LM_mu, LM_lambda);
                            DijkstraShortestPaths <DirectedWeightedSparseGraph <string>, string> dijkstra
                                         = new DijkstraShortestPaths <DirectedWeightedSparseGraph <string>, string>(graph, "Start");//考虑该旅客到达时间
                            var nodepath = dijkstra.ShortestPathTo("End");
                            if (nodepath == null)
                            {
                                throw new System.Exception("No path found");
                            }
                            else
                            {
                                w[train][station] = new PricePath(graph, nodepath);
                            }
                        });
                        SubTasks.Add(ta);
                    }
                }
                Task.WaitAll(SubTasks.ToArray());

                foreach (var edge in y.Keys.ToArray())//更新y
                {
                    var sta   = edge.Source.Station;
                    var train = basicGraph.GetTrainByReservationLink(edge);
                    y[edge] = w[train][sta].GetWrapPoints(edge.Destination.Price, edge.Source.Time).Any();
                }
                #endregion

                #region 计算拉格朗日函数值作为下界

                decimal templowerBound       = 0m;
                decimal templowerBound_part1 = 0m;
                decimal templowerBound_part2 = 0m;
                decimal templowerBound_part3 = 0m;
                decimal templowerBound_part4 = 0m;
                Dictionary <CustomerArrival, decimal> lbValueDic
                    = new Dictionary <CustomerArrival, decimal>();
                //1 计算在基础网络中的路径cost
                foreach (CustomerArrival customer in _ctx.Pal)
                {
                    lbValueDic.Add(customer, objgraph.GetPathCost(x[customer]));
                    templowerBound_part1 += lbValueDic[customer];
                }

                //2计算BRUE项
                templowerBound_part2 += _ctx.Pal.Sum(c => pathDict[c].Sum(p =>
                {
                    decimal secondItem = 0m;
                    secondItem        += basicGraph.GetPathCost(x[c]) - basicGraph.GetPathCost(p) - _ctx.SitaDic[c.Customer.MarSegID];
                    secondItem        -= (p.ReservationArc != null && y[p.ReservationArc]) ? 0 : bigM;
                    return(secondItem * LM_mu[c][p]);
                }));

                //3计算In-train Capacity项
                Dictionary <IServiceSegment, int> ServiceDic = _ctx.Wor.RailwayTimeTable
                                                               .Trains.SelectMany(i => i.ServiceSegments)
                                                               .ToDictionary(i => i, i => 0);//当前service segment使用情况

                foreach (var p in x.Values)
                {
                    foreach (IServiceSegment seg in p.GetSegments(basicGraph))
                    {
                        ServiceDic[seg] += 1;
                    }
                }
                foreach (var train in _ctx.Wor.RailwayTimeTable.Trains)
                {
                    foreach (var seg in train.ServiceSegments)
                    {
                        templowerBound_part3 += LM_rho[seg] * (ServiceDic[seg] - train.Carriage.Chairs.Count());
                    }
                }

                //4 计算reservation constraint 项
                Dictionary <IEdge <TravelHyperNode>, int> reservationDic
                    = new Dictionary <IEdge <TravelHyperNode>, int>();
                foreach (var p in x.Values)
                {
                    if (reservationDic.ContainsKey(p.ReservationArc))
                    {
                        reservationDic[p.ReservationArc] += 1;
                    }
                    else
                    {
                        reservationDic.Add(p.ReservationArc, 1);
                    }
                }
                foreach (var pair in y.Keys)
                {
                    //y是所有的reservation 的集合 reservationDic 是已经使用的reservation 集合
                    var res = reservationDic.Keys.FirstOrDefault(i => i.Source == pair.Source && i.Destination == pair.Destination);
                    templowerBound_part4 += LM_lambda[pair] * ((res != null ? reservationDic[res] : 0) - (y[pair] ? bigM : 0));
                }

                templowerBound = templowerBound_part1 + templowerBound_part2 + templowerBound_part3 + templowerBound_part4;

                //Log($"Lower Bound = { Math.Round(templowerBound, 2)}," +
                //   $"({ Math.Round(templowerBound_part1, 2) }" +
                //   $"+{ Math.Round(templowerBound_part2, 2)}" +
                //   $"+{ Math.Round(templowerBound_part3, 2)}" +
                //   $"+{ Math.Round(templowerBound_part4, 2)})");

                PrintLBSolution(DpnAlgorithm.GetTravelPathString(_ctx, adapter, objgraph, x, lbValueDic));
                #endregion

                #region 更新乘子
                if (flag)
                {
                    decimal LagLowerBound = Convert.ToDecimal(model.GetValue(theta));
                    Log($"LagLower Bound = { LagLowerBound }");
                    Log($"Lower Bound = { templowerBound }");
                    lowerBound = Math.Max(lowerBound, templowerBound);

                    decimal lagGap = LagLowerBound - templowerBound;

                    if (lagGap <= 0)//判断拉格朗日对偶问题是否达到最优
                    {
                        Log($"求解终止:对偶函数已最优。");
                        break;
                    }
                    else
                    {
                        /* 更新乘子值 */
                        foreach (var pair in dual_rho)
                        {
                            LM_rho[pair.Key] = Convert.ToDecimal(model.GetValue(pair.Value));
                        }
                        foreach (var pair in dual_lambda)
                        {
                            LM_lambda[pair.Key] = Convert.ToDecimal(model.GetValue(pair.Value));
                        }
                        foreach (CustomerArrival customer in _ctx.Pal)
                        {
                            foreach (var path in pathDict[customer])
                            {
                                LM_mu[customer][path] = Convert.ToDecimal(model.GetValue(dual_mu[customer][path]));
                            }
                        }
                    }
                }
                else /* 如果对偶问题无可行解,通过次梯度的方式更新乘子 */
                {
                    //decimal step = 1.618m / (iter + 1);
                    //foreach (CustomerArrival c in _ctx.Pal)//更新mu
                    //{
                    //    foreach (TravelPath p in pathDict[c])
                    //    {
                    //        Grad_mu[c][p] = basicGraph.GetPathCost(x[c]) - basicGraph.GetPathCost(p) - _ctx.SitaDic[c.Customer.MarSegID]
                    //            - ((p.ReservationArc != null && y[p.ReservationArc]) ? 0 : bigM);
                    //        LM_mu[c][p] = Math.Max(0, LM_mu[c][p] + step * Grad_mu[c][p]);
                    //    }
                    //}
                    //foreach (var pair in y.Keys) //更新lambda
                    //{
                    //    var res = reservationDic.Keys.FirstOrDefault(i => i.Source == pair.Source && i.Destination == pair.Destination);
                    //    Grad_lambda[pair] = ((res != null ? reservationDic[res] : 0) - (y[pair] ? bigM : 0));
                    //    LM_lambda[pair] = Math.Max(0, LM_lambda[pair] + step * Grad_lambda[pair]);
                    //}
                    //foreach (var train in _ctx.Wor.RailwayTimeTable.Trains)//更新rho
                    //{
                    //    foreach (var seg in train.ServiceSegments)
                    //    {
                    //        Grad_rho[seg] = ServiceDic[seg] - train.Carriage.Chairs.Count();
                    //        LM_rho[seg] = Math.Max(0, LM_rho[seg] + step * Grad_rho[seg]);
                    //    }
                    //}
                }

                #endregion

                #region 求解拉格朗日对偶问题

                /* 求解 几何乘子 */
                // 增加 一个约束
                INumExpr exp = model.NumExpr();

                //2 计算BRUE项
                foreach (var c in _ctx.Pal)
                {
                    foreach (var p in pathDict[c])
                    {
                        decimal secondItem = 0m;
                        secondItem += basicGraph.GetPathCost(x[c]) - basicGraph.GetPathCost(p) - _ctx.SitaDic[c.Customer.MarSegID];
                        secondItem -= (p.ReservationArc != null && y[p.ReservationArc]) ? 0 : bigM;
                        exp         = model.Sum(exp, model.Prod(Convert.ToDouble(secondItem), dual_mu[c][p]));
                    }
                }

                //3计算In-train Capacity项 (这里直接用了计算下界时候的 Service_dic
                foreach (var train in _ctx.Wor.RailwayTimeTable.Trains)
                {
                    foreach (var seg in train.ServiceSegments)
                    {
                        exp = model.Sum(exp, model.Prod(Convert.ToDouble(ServiceDic[seg]
                                                                         - train.Carriage.Chairs.Count()), dual_rho[seg]));
                    }
                }

                //4 计算reservation constraint 项 (这里直接用了计算下界时候的 reservationDic
                foreach (var pair in y.Keys)
                {
                    var res = reservationDic.Keys.FirstOrDefault(i => i.Source == pair.Source &&
                                                                 i.Destination == pair.Destination);
                    exp = model.Sum(exp, model.Prod(Convert.ToDouble(((res != null ? reservationDic[res] : 0)
                                                                      - (y[pair] ? bigM : 0))), dual_lambda[pair]));
                }

                model.AddGe(model.Sum(Convert.ToDouble(templowerBound_part1), exp), theta);

                /* Trust-Region */
                //var trExpr = model.Add()

                flag = model.Solve();
                Log($"Is Dual Problem Feasible: { flag }");

                #endregion

                #region 通过一个启发式规则计算上界(按照w模拟到达)

                var pathcost     = lbValueDic.ToDictionary(i => i.Key, i => i.Value);
                var x_least      = x.ToDictionary(i => i.Key, i => i.Value);//当前w下每个旅客的最短路径
                var x_upperbound = x.ToDictionary(i => i.Key, i => i.Value);
                var x_controlled = x.ToDictionary(i => i.Key, i => i.Value);

                #region 1-构建当前y下的最优x值
                SubTasks.Clear();
                foreach (CustomerArrival customer in _ctx.Pal)// 求解x
                {
                    Task ta = factory.StartNew(() =>
                    {
                        var controlledLRxgraph = new ControlledLRxTravelHyperNetwork(
                            _ctx, adapter, objgraph, customer, pathDict, LM_rho, LM_mu, LM_lambda, y);
                        controlledLRxgraph.Build();
                        var ori = (_ctx.Wor.Mar[customer.Customer.MarSegID] as IRailwayMarketSegment).OriSta;
                        var des = (_ctx.Wor.Mar[customer.Customer.MarSegID] as IRailwayMarketSegment).DesSta;

                        TravelHyperNode startNode = new TravelHyperNode()
                        {
                            Time    = adapter.ConvertToDiscreteTime(customer.ArriveTime),
                            Station = ori,
                            Price   = 0
                        };
                        TravelHyperNode endNode = new TravelHyperNode()
                        {
                            Time    = adapter.Horizon + 1440,
                            Station = des,
                            Price   = 0
                        };

                        DijkstraShortestPaths <DirectedWeightedSparseGraph <TravelHyperNode>, TravelHyperNode> dijkstra
                            = new DijkstraShortestPaths <DirectedWeightedSparseGraph <TravelHyperNode>, TravelHyperNode>
                                  (controlledLRxgraph, startNode);//考虑该旅客到达时间

                        if (!dijkstra.HasPathTo(endNode))
                        {
                            throw new System.Exception("没有路径!");
                        }
                        else
                        {
                            x_controlled[customer] = new TravelPath(controlledLRxgraph, dijkstra.ShortestPathTo(endNode));
                        }
                    });
                    SubTasks.Add(ta);
                }
                Task.WaitAll(SubTasks.ToArray());
                #endregion

                # region 2-构建当前y下的出行最小值
                var solutiongraph = new ControlledTravelHyperNetwork(_ctx, adapter, y);
                solutiongraph.Build();
                Parallel.ForEach(_ctx.Pal, customer =>                //foreach (var customer in _ctx.Pal)//求此网络下每个旅客的最短路径
                {
                    var ori = (_ctx.Wor.Mar[customer.Customer.MarSegID] as IRailwayMarketSegment).OriSta;
                    var des = (_ctx.Wor.Mar[customer.Customer.MarSegID] as IRailwayMarketSegment).DesSta;

                    TravelHyperNode startNode = new TravelHyperNode()
                    {
                        Time    = adapter.ConvertToDiscreteTime(customer.ArriveTime),
                        Station = ori,
                        Price   = 0
                    };

                    TravelHyperNode endNode = new TravelHyperNode()
                    {
                        Time    = adapter.Horizon + 1440,
                        Station = des,
                        Price   = 0
                    };

                    DijkstraShortestPaths <DirectedWeightedSparseGraph <TravelHyperNode>, TravelHyperNode> dijkstra
                        = new DijkstraShortestPaths <DirectedWeightedSparseGraph <TravelHyperNode>, TravelHyperNode>
                              (solutiongraph, startNode);

                    if (!dijkstra.HasPathTo(endNode))
                    {
                        throw new System.Exception("没有路径!");
                    }
                    else
                    {
                        x_least[customer] = new TravelPath(solutiongraph, dijkstra.ShortestPathTo(endNode));
                    }
                });
                #endregion

                #region 3-修复可行解
                var solutiongraphTemp = new SimNetwork(_ctx, adapter, y);//建立仿真网络
                solutiongraphTemp.Build();
                foreach (var customer in _ctx.Pal)
                {
                    x_upperbound[customer] = x_controlled[customer];
                    TravelPath path = x_controlled[customer];

                    if (!solutiongraphTemp.IsPathFeasible(path) ||
                        solutiongraphTemp.GetPathCost(path) > solutiongraph.GetPathCost(x_least[customer]) + _ctx.SitaDic[customer.Customer.MarSegID])//如果违反了容量约束或者BRUE约束
                    {
                        var ori = (_ctx.Wor.Mar[customer.Customer.MarSegID] as IRailwayMarketSegment).OriSta;
                        var des = (_ctx.Wor.Mar[customer.Customer.MarSegID] as IRailwayMarketSegment).DesSta;
                        DijkstraShortestPaths <DirectedWeightedSparseGraph <TravelHyperNode>, TravelHyperNode> dijkstra
                            = new DijkstraShortestPaths <DirectedWeightedSparseGraph <TravelHyperNode>, TravelHyperNode>(solutiongraphTemp, new TravelHyperNode()
                        {
                            Time    = adapter.ConvertToDiscreteTime(customer.ArriveTime),
                            Station = ori,
                            Price   = 0
                        });

                        //重新查找路径,如果存在路径
                        if (dijkstra.HasPathTo(new TravelHyperNode()
                        {
                            Time = adapter.Horizon + 1440,
                            Station = des,
                            Price = 0
                        }))
                        {
                            x_upperbound[customer] = new TravelPath(solutiongraphTemp, dijkstra.ShortestPathTo(new TravelHyperNode()
                            {
                                Time    = adapter.Horizon + 1440,
                                Station = des,
                                Price   = 0
                            }));
                            if (solutiongraphTemp.GetPathCost(x_upperbound[customer]) <= //满足BRUE约束
                                solutiongraph.GetPathCost(x_least[customer]) + _ctx.SitaDic[customer.Customer.MarSegID])
                            {
                                path = x_upperbound[customer];
                            }
                            else
                            {
                                hasFeasibleSolution = false;
                                break;
                            }
                        }
                        else
                        {
                            hasFeasibleSolution = false;
                            break;
                        }
                    }

                    pathcost[customer] = objgraph.GetPathCost(path);

                    //加载路径
                    foreach (var seg in path.GetSegments(basicGraph))
                    {
                        solutiongraphTemp.AddUsage(seg, 1);
                    }
                }
                var tempUpperbound = _ctx.Pal.Sum(c => objgraph.GetPathCost(x_upperbound[c]));
                #endregion

                //如果有最优解再更新上界
                bool hasBetterUpperbound = tempUpperbound < upperBound;
                if (hasFeasibleSolution)
                {
                    upperBound = Math.Min(upperBound, tempUpperbound);
                }
                Log($"Upper Bound = {  Math.Round(tempUpperbound, 2) },找到可行解 : { hasFeasibleSolution.ToString()}");
                #endregion

                #region  Terminatation 判定
                Log($"Upper Bound = { tempUpperbound }");
                decimal absoluteGap = 0;
                string  gapStr      = "";
                //如果上限是无穷,那么此时gap也是无穷
                if (upperBound == decimal.MaxValue || lowerBound == decimal.MinValue)
                {
                    absoluteGap = decimal.MaxValue;
                    gapStr      = $"+∞";
                }
                else
                {
                    absoluteGap = upperBound - lowerBound;
                    gapStr      = $"{ Math.Round(absoluteGap, 2)}";
                }


                if (absoluteGap < terminalFactor && absoluteGap > 0)
                {
                    Log($"求解终止:Gap以满足终止条件,Gap={ absoluteGap }");
                    break;
                }

                Log($"Total Gap = { gapStr }");
                #endregion

                #region 输出信息

                //SendMessage($"#Iteration Number, Lower Bound, Upper Bound, Best Lower Bound, Best Upper Bound, Total Gap(%) ");
                PrintIterationInfo($"#{iter},{ Math.Round(templowerBound) },{ Math.Round(tempUpperbound) },{ Math.Round(lowerBound)}" +
                                   $",{ Math.Round(upperBound) },{ gapStr }");

                string ss = "###,";
                foreach (var s in LM_rho)
                {
                    ss += ($"{s.Key.ToString()}:{ s.Value.ToString() },");
                }
                PrintIterationInfo(ss);

                if (hasFeasibleSolution && hasBetterUpperbound)
                {
                    ObjValue = pathcost.Sum(i => i.Value);
                    PrintSolution(
                        DpnAlgorithm.GetTravelPathString(_ctx, adapter, solutiongraph, x_upperbound, pathcost),
                        DpnAlgorithm.GetPricingPathString(_ctx, adapter, w));
                }

                #endregion

                Log($"--------------第{iter}轮求解结束--------------");
            }
Ejemplo n.º 21
0
        public Task RemoveAllSubTasks()
        {
            SubTasks.Clear();

            return(this);
        }
Ejemplo n.º 22
0
 public ActionResult AddSubTasks(SubTasks subTask)
 {
     TasksHelper.TaskHelper.AddSubTask(subTask);
     return(RedirectToAction("SubTasks", new { taskId = subTask.TaskId }));
 }
Ejemplo n.º 23
0
        private FlowDocument BuildDocument()
        {
            var doc = new FlowDocument();

            doc.LineStackingStrategy = System.Windows.LineStackingStrategy.BlockLineHeight;
            doc.LineHeight           = 12;
            doc.Blocks.Add(new Paragraph(new Bold(new Run("Summary"))));
            doc.Blocks.Add(new Paragraph(new Run(" " + Title)));
            doc.Blocks.Add(new Paragraph(new Bold(new Run("Description"))));
            doc.Blocks.Add(new Paragraph(new Run(" " + Description)));

            doc.Blocks.Add(new Paragraph(new Bold(new Run("Url"))));
            var url = new Hyperlink(new Run(Url.ToString()));

            doc.Blocks.Add(new Paragraph(url));
            doc.Blocks.Add(new Paragraph(new Bold(new Run("Parent Story"))));
            var parentUrl = new Hyperlink(new Run(ParentStoryUrl.ToString()));

            parentUrl.NavigateUri = ParentStoryUrl;
            doc.Blocks.Add(new Paragraph(parentUrl));

            doc.Blocks.Add(new Paragraph(new Italic(new Run("Status: " + Status.ToString()))));

            doc.Blocks.Add(new Paragraph(new Italic(new Run("Date Started: " + DateStarted.Value.ToString("yyyy-MM-dd hh:mm:ss")))));
            if (DateEnded.HasValue && DateEnded.Value != DateTime.MinValue)
            {
                doc.Blocks.Add(new Paragraph(new Italic(new Run("Date Ended: " + DateEnded.Value.ToString("yyyy-MM-dd hh:mm:ss")))));
            }

            if (Attachments.Any())
            {
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Attachments"))));
                foreach (var item in Attachments)
                {
                    var itemUri = new Uri(item.Value);
                    var itemUrl = new Hyperlink(new Run(item.Value));
                    doc.Blocks.Add(new Paragraph(itemUrl));
                }
            }

            if (AcceptanceCriteria.Any())
            {
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Acceptance Criteria"))));
                foreach (var item in AcceptanceCriteria)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" + " + item.Value)));
                }
            }

            if (DeveloperCriteria.Any())
            {
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Development Criteria"))));
                foreach (var item in DeveloperCriteria)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" + " + item.Value)));
                }
            }

            var i = 0;
            var j = 0;

            if (KeyIdentifiers.Any())
            {
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Key Identifiers"))));
                foreach (var item in KeyIdentifiers)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" " + (++i).ToString() + ". " + item.Description)));

                    if (item.Questions.Any())
                    {
                        j = 0;
                        doc.Blocks.Add(new Paragraph(new Italic(new Run(" Questions"))));
                        foreach (var q in item.Questions)
                        {
                            doc.Blocks.Add(new Paragraph(new Run("   " + (++j).ToString() + ".Q. " + q.Ask)));
                            doc.Blocks.Add(new Paragraph(new Run("     A. " + q.Answer)));
                        }
                    }
                }
            }

            if (Issues.Any())
            {
                i = 0;
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Issues"))));
                foreach (var item in Issues)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" " + (++i).ToString() + ". " + item.Description)));
                    doc.Blocks.Add(new Paragraph(new Italic(new Run("  Is Open: " + item.IsOpen.ToString()))));
                }
            }

            if (Queries.Any())
            {
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Queries"))));
                foreach (var item in Queries)
                {
                    var itemUri = new Uri(item.Value);
                    var itemUrl = new Hyperlink(new Run(item.Value));
                    doc.Blocks.Add(new Paragraph(itemUrl));
                }
            }

            if (Scripts.Any())
            {
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Scripts"))));
                foreach (var item in Scripts)
                {
                    var itemUri = new Uri(item.Value);
                    var itemUrl = new Hyperlink(new Run(item.Value));
                    doc.Blocks.Add(new Paragraph(itemUrl));
                }
            }

            if (TestCases.Any())
            {
                i = 0;
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Test Cases"))));
                foreach (var item in TestCases)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" " + (++i).ToString() + ". " + item.Description)));
                    doc.Blocks.Add(new Paragraph(new Italic(new Run("  Status: " + item.Status.ToString()))));

                    if (item.Steps.Any())
                    {
                        j = 0;
                        doc.Blocks.Add(new Paragraph(new Italic(new Run(" Steps"))));
                        foreach (var q in item.Steps)
                        {
                            doc.Blocks.Add(new Paragraph(new Run("   " + (++j).ToString() + ". " + q.Value)));
                        }
                    }
                }
            }

            if (Checkups.Any())
            {
                i = 0;
                doc.Blocks.Add(new Paragraph(new Bold(new Run("Checkups"))));
                foreach (var item in Checkups)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" " + (++i).ToString() + ". " + item.Description)));
                    doc.Blocks.Add(new Paragraph(new Italic(new Run("  Applied: " + item.Applied.ToString()))));
                }
            }

            if (SubTasks.Any())
            {
                i = 0;
                doc.Blocks.Add(new Paragraph(new Bold(new Run("SubTasks"))));
                foreach (var item in SubTasks)
                {
                    doc.Blocks.Add(new Paragraph(new Run(" " + (++i).ToString() + ". " + item.Title)));
                    doc.Blocks.Add(new Paragraph(new Italic(new Run("  Status: " + item.Status))));
                }
            }

            return(doc);
        }
Ejemplo n.º 24
0
 public void AddSubTask(ITask task)
 {
     SubTasks.Add(new TaskViewModel(task.Title, task.DueDate));
 }
Ejemplo n.º 25
0
 public PrepareMeatMethod2()
 {
     SubTasks.Add(ExampleDomain.Instance.GetTask(DefinedTaskEnum.MoveToTask));
     SubTasks.Add(ExampleDomain.Instance.GetTask(DefinedTaskEnum.EatMeatTask));
 }
Ejemplo n.º 26
0
 public virtual void AddSubTask(LogTask task)
 {
     SubTasks.Add(task);
 }
Ejemplo n.º 27
0
 public Task(string name) : base(name)
 {
     subtasks        = new SubTasks();
     subtasks.parent = this;
     _date           = new SerializableDate();
 }
Ejemplo n.º 28
0
        public Task RemoveSubTask(Task task)
        {
            SubTasks.Remove(task);

            return(this);
        }