Example #1
0
        private List <Processor> getAllFreeProcOnStep(int stepNumber, List <DiagramRow> rows)
        {
            List <Processor> freeProcessors = new List <Processor>();
            DiagramRow       row            = rows.ElementAt(stepNumber);

            for (int i = 0; i < row.states.Length; i++)
            {
                if (row.states[i].task == null)
                {
                    freeProcessors.Add(procMap[i]);
                }
            }
            return(freeProcessors);
        }
Example #2
0
        private List <DiagramRow> initRows()
        {
            List <DiagramRow> rows = new List <DiagramRow>();

            for (int i = 0; i < 10000; i++)
            {
                DiagramRow row = new DiagramRow();
                row.number = i;
                row.states = new DiagramState[procMap.Count];
                for (int j = 0; j < row.states.Length; j++)
                {
                    row.states[j] = new DiagramState();
                }
                rows.Add(row);
            }
            return(rows);
        }
Example #3
0
        public String[][] buildPlan()
        {
            buildProc();
            buildTasks();
            List <DiagramRow> rows = initRows();

            while (!isAllTaskFinished())
            {
                for (int i = 0; i < quee.getQueue().Count; i++)
                {
                    Task task = taskMap[quee.getQueue().ElementAt(i)];
                    if (task.state == TaskState.FINISHED)
                    {
                        continue;
                    }
                    int stepForDeploy = getStepForDeployTask(task, rows);
                    if (stepForDeploy == Int32.MinValue)
                    {
                        continue;
                    }
                    int[] planTaskInfo = plann(task, stepForDeploy, rows);
                    addTaskToDiagram(task, planTaskInfo, rows);
                }
            }
            int maxRowCount = 0;

            for (int i = 0; i < rows.Count; i++)
            {
                DiagramRow row = rows.ElementAt(i);
                if (row.usedProc.Count != 0)
                {
                    continue;
                }
                bool isUseState = false;
                for (int j = 0; j < row.states.Length; j++)
                {
                    DiagramState state = row.states[j];
                    if (state.transm.Count != 0 || state.task != null)
                    {
                        isUseState = true;
                        break;
                    }
                }
                if (isUseState)
                {
                    continue;
                }
                maxRowCount = i;
                break;
            }
            String[][] result = new String[maxRowCount][];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = new String[procesors.Length];
                for (int j = 0; j < procesors.Length; j++)
                {
                    if (rows.ElementAt(i).states[j].task != null)
                    {
                        Task task = rows.ElementAt(i).states[j].task;
                        result[i][j] = "Task " + task.number + ";";
                    }
                }
            }
            for (int i = 0; i < result.Length; i++)
            {
                for (int j = 0; j < procesors.Length; j++)
                {
                    DiagramState diagramState = rows.ElementAt(i).states[j];
                    for (int k = 0; k < diagramState.transm.Count; k++)
                    {
                        Transmission transm   = diagramState.transm.ElementAt(k);
                        Task         taskFrom = taskMap[transm.taskFromNumber];
                        Task         taskTo   = taskMap[transm.taskToNumber];
                        if (j == taskTo.procNumber)
                        {
                            result[i][j] += "Receive from ";
                        }
                        else
                        {
                            result[i][j] += "Send from ";
                        }
                        result[i][j] += taskFrom.number + " to " + taskTo.number + ";";
                    }
                }
            }
            return(result);
        }