示例#1
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Enter tasks in the following format: c1,c2,...  where X is cost");
                Console.WriteLine("Type END to finish entering tasks");

                var  counter = 0;
                Plan plan    = new Plan();

                while (true)
                {
                    Console.Write($"Task #{++counter}: ");
                    String input = Console.ReadLine();
                    plan.AddTask(new Task(input));
                    if (input.Trim().ToLower() == "end")
                    {
                        break;
                    }
                }

                Bucket bucket         = plan.Simulate();
                var    calculatedTime = bucket.CalculateTime();
                output(plan, bucket, calculatedTime);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetBaseException().Message);
            }
        }
示例#2
0
            public void AddTaskFromFile(string content)
            {
                var nnParams = NnParam.NewParamsFromList(content);

                foreach (NnParam param in nnParams)
                {
                    Plan.AddTask(param);
                }
            }
示例#3
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Enter tasks in the following format: c1,c2,...\nwherex is cost");
                Console.WriteLine("Type END to finish entering tasks");

                int  i    = 0;
                Plan plan = new Plan();

                while (true)
                {
                    Console.Write($"Task #{++i}: ");
                    String input = Console.ReadLine();

                    if (input.Trim().ToUpper() == "END")
                    {
                        break;
                    }

                    plan.AddTask(new Task(input));
                }

                Bucket bucket         = plan.Simulate();
                var    calculatedTime = bucket.CalculateTime();
                Console.WriteLine($"After probing {plan.NumberOfIterations} random plans, the results are:");
                Console.WriteLine($"Minimum = {calculatedTime.Item1} days");
                Console.WriteLine($"Maximum = {calculatedTime.Item2} days");
                Console.WriteLine($"Average = {calculatedTime.Item3} days");

                Console.WriteLine("Probability of finishing the plan in:\n" + bucket);

                bucket.ToAccumulated();

                Console.WriteLine("Accumulated probability of finishing the plan in or before:\n" + bucket);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occured: " + e.Message);
            }
        }
示例#4
0
            public NnTaskData?AddTask(NnParamForm param)
            {
                if (!param.IsFilled)
                {
                    return(null);
                }
                NnParam?nnParam;

                if ((nnParam = param.ToNnParam()) == null)
                {
                    return(null);
                }

                var task = Plan.AddTask(nnParam);

                if (task == null)
                {
                    return(null);
                }

                return(new NnTaskData(task, nnParam));
            }
示例#5
0
    //-----------------------------------------------------------------------------------------------
    public Plan HandleAgentPlanRequest(AgentPlanRequest request)
    {
        int currentIndex = request.m_nextTaskIndex;

        // plan finished
        if (IsPlanFinished(currentIndex))
        {
            return(null);
        }

        // Can't get a new plan if syncing
        if (m_isSyncing && (currentIndex > m_syncIndex))
        {
            return(null);
        }

        Plan agentPlan     = new Plan();
        bool canGetNewTask = true;

        while (canGetNewTask)
        {
            PrimitiveTask taskToGet = m_activeStrategyPlan.TaskList[currentIndex];
            if (taskToGet.IsClaimed)
            {
                ++currentIndex;
                continue;
            }

            // Handle modifiers on task
            uint taskMods = taskToGet.ModifierMask;

            // Blocking tasks mean we can't get more tasks until we're done
            if ((taskMods & (byte)Task.eModifier.BLOCKING_MODIFIER) != 0)
            {
                canGetNewTask = false;
            }

            // Sync tasks require everyone to reach the task before continuing
            if ((taskMods & (byte)Task.eModifier.SYNC_MODIFIER) != 0)
            {
                m_isSyncing = true;
                m_syncIndex = currentIndex;
                ++m_syncCount;

                // extra check to see if done syncing
                if (m_syncCount == m_numActiveAgents)
                {
                    StopSync();
                    ++currentIndex;
                    agentPlan.ClearPlan();
                    continue;
                }
                else
                {
                    canGetNewTask = false;
                }
            }

            // Reservable tasks can be claimed and ran only once
            if ((taskMods & (byte)Task.eModifier.RESERVABLE_MODIFIER) != 0)
            {
                taskToGet.Claim();
            }

            // Add task to plan and increment index
            PrimitiveTask taskClone = taskToGet.Clone() as PrimitiveTask;
            taskClone.Op.AssignVariables(request.m_agent);

            agentPlan.AddTask(taskClone);
            ++currentIndex;

            if (m_activeStrategyPlan.IsIndexOutOfPlan(currentIndex))
            {
                canGetNewTask = false;
            }
        }

        request.m_agent.CurrentPlanIndex = currentIndex;
        return(agentPlan);
    }