Ejemplo n.º 1
0
        public static JobSequence ToJobSequence(this IEnumerable <Job> jobs)
        {
            JobSequence jobSequence = new JobSequence();

            jobs.ForEach(job => jobSequence.Add(job));
            return(jobSequence);
        }
Ejemplo n.º 2
0
        /// <summary>Create a runnable job for the F4P simulations</summary>
        /// <param name="FilesToRun">The files to run.</param>
        /// <param name="ApsimExecutable">APSIM.exe path. Can be null.</param>
        /// <returns>A runnable job for all simulations</returns>
        protected override JobManager.IRunnable CreateRunnableJob(string jobName, string jobXML, string workingDirectory, string ApsimExecutable)
        {
            // Create a sequential job.
            JobSequence completeJob = new JobSequence();
            completeJob.Jobs = new List<JobManager.IRunnable>();

            List<JobManager.IRunnable> jobs = new List<JobManager.IRunnable>();

            // Save f4p.xml to working folder.
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(jobXML);
            doc.Save(Path.Combine(workingDirectory, "f4p.xml"));

            Farm4Prophet spec = Farm4ProphetUtility.Farm4ProphetFromXML(jobXML);
            List<AusFarmSpec> simulations = Farm4ProphetToAusFarm.ToAusFarm(spec);

            //writes the sdml files to the workingDirectory and returns a list of names
            string[] files = AusFarmFiles.Create(simulations, workingDirectory);

            string binDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            //for each simulation
            for (int i = 0; i < files.Length; i++)
            {
                RunnableJobs.AusFarmJob job = new RunnableJobs.AusFarmJob(
                 jobName: jobName,
                 fileName: Path.Combine(workingDirectory, files[i]),
                 arguments: "");
                jobs.Add(job);
            }

            completeJob.Jobs.Add(new JobParallel() { Jobs = jobs });

            return completeJob;
        }
Ejemplo n.º 3
0
        /// <summary>Called to start the job.</summary>
        /// <param name="jobManager">The job manager running this job.</param>
        /// <param name="workerThread">The thread this job is running on.</param>
        public void Run(JobManager jobManager, BackgroundWorker workerThread)
        {
            JobSequence   parentJob       = new JobSequence();
            JobParallel   simulationJobs  = new JobParallel();
            List <string> simulationNames = new List <string>();

            FindAllSimulationsToRun(model, simulationJobs, simulationNames);
            parentJob.Jobs.Add(simulationJobs);
            parentJob.Jobs.Add(new RunAllCompletedEvent(simulations));

            // IF we are going to run all simulations, we can delete all tables in the DataStore. This
            // will clean up order of columns in the tables and removed unused ones.
            // Otherwise just remove the unwanted simulations from the DataStore.
            DataStore store = Apsim.Child(simulations, typeof(DataStore)) as DataStore;

            if (model is Simulations)
            {
                store.DeleteAllTables(true);
            }
            else
            {
                store.RemoveUnwantedSimulations(simulations, simulationNames);
            }
            store.Disconnect();

            if (runTests)
            {
                foreach (Tests tests in Apsim.ChildrenRecursively(model, typeof(Tests)))
                {
                    parentJob.Jobs.Add(tests);
                }
            }
            jobManager.AddChildJob(this, parentJob);
        }
Ejemplo n.º 4
0
        /// <summary>Called to start the job.</summary>
        /// <param name="jobManager">The job manager running this job.</param>
        /// <param name="workerThread">The thread this job is running on.</param>
        public void Run(JobManager jobManager, BackgroundWorker workerThread)
        {
            // IF we are going to run all simulations, we can delete all tables in the DataStore. This
            // will clean up order of columns in the tables and removed unused ones.
            // Otherwise just remove the unwanted simulations from the DataStore.
            DataStore store = Apsim.Child(simulations, typeof(DataStore)) as DataStore;
            if (model is Simulations)
                store.DeleteAllTables();
            else
                store.RemoveUnwantedSimulations(simulations);
            store.Disconnect();

            JobSequence parentJob = new JobSequence();
            JobParallel simulationJobs = new JobParallel();
            FindAllSimulationsToRun(model, simulationJobs);
            parentJob.Jobs.Add(simulationJobs);
            parentJob.Jobs.Add(new RunAllCompletedEvent(simulations));

            if (runTests)
            {
                foreach (Tests tests in Apsim.ChildrenRecursively(model, typeof(Tests)))
                    parentJob.Jobs.Add(tests);
            }
            jobManager.AddChildJob(this, parentJob);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates an empty MachineLayer; No disjunctive arcs shall be present.
 /// </summary>
 public SequencingLayer(IGraphLayer graphLayer)
 {
     GraphLayer = graphLayer;
     _sequences = new IJobSequence[Problem.MachineAndConnectionCount];
     for (int i = 0; i < Problem.MachineAndConnectionCount; i++)
     {
         _sequences[i] = new JobSequence(i, GraphLayer);
     }
 }
Ejemplo n.º 6
0
        public void Write(JobSequence jobSequence, FileInfo scheduledJobFile)
        {
            Check.Require(scheduledJobFile != null,
                "file cannot be null", new ArgumentNullException("scheduledJobFile"));
            Check.Require(jobSequence != null,
                "jobSequence cannot be null", new ArgumentNullException("jobSequence"));

            var serializer = (new XmlSerializerFactory()).CreateSerializer(
                typeof(JobSequence));
            serializer.Serialize(scheduledJobFile.OpenWrite(), jobSequence);
        }
Ejemplo n.º 7
0
        /// <summary>Create a runnable job for the YP simulations</summary>
        /// <param name="FilesToRun">The files to run.</param>
        /// <param name="ApsimExecutable">APSIM.exe path. Can be null.</param>
        /// <returns>A runnable job for all simulations</returns>
        protected override JobManager.IRunnable CreateRunnableJob(string jobName, string jobXML, string workingDirectory, string ApsimExecutable)
        {
            // Create a sequential job.
            JobSequence completeJob = new JobSequence();
            completeJob.Jobs = new List<JobManager.IRunnable>();

            List<JobManager.IRunnable> jobs = new List<JobManager.IRunnable>();

            // Create a YieldProphet object from our YP xml file
            YieldProphet spec = YieldProphetUtility.YieldProphetFromXML(jobXML, workingDirectory);

            string fileBaseToWrite;
            if (spec.ReportType == YieldProphet.ReportTypeEnum.None && spec.ReportName != null)
                fileBaseToWrite = spec.ReportName;
            else
                fileBaseToWrite = "YieldProphet";

            // Convert YieldProphet spec into a simulation set.
            List<APSIMSpec> simulations = YieldProphetToAPSIM.ToAPSIM(spec);

            // Create all the files needed to run APSIM.
            string apsimFileName = APSIMFiles.Create(simulations, workingDirectory, fileBaseToWrite + ".apsim");

            // Fill in calculated fields.
            foreach (Paddock paddock in spec.Paddock)
                YieldProphetUtility.FillInCalculatedFields(paddock, paddock.ObservedData, workingDirectory);

            // Save YieldProphet.xml to working folder.
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(YieldProphetUtility.YieldProphetToXML(spec));
            doc.Save(Path.Combine(workingDirectory, fileBaseToWrite + ".xml"));

            // Convert .apsim file to sims so that we can run ApsimModel.exe rather than Apsim.exe
            // This will avoid using the old APSIM job runner. It assumes though that there are 
            // no other APSIMJob instances running in the workingDirectory. This is because it
            // looks and runs all .sim files it finds in the workingDirectory.
            JobParallel simJobs = new JobParallel();
            simJobs.Jobs = new List<JobManager.IRunnable>();
            string[] simFileNames = CreateSimFiles(apsimFileName, workingDirectory);
            foreach (string simFileName in simFileNames)
            {
                if (simFileName == null || simFileName.Trim() == string.Empty)
                    throw new Exception("Blank .sim file names found for apsim file: " + apsimFileName);
                simJobs.Jobs.Add(new RunnableJobs.APSIMJob(simFileName, workingDirectory, ApsimExecutable, true));
            }
            completeJob.Jobs.Add(simJobs);
            completeJob.Jobs.Add(new RunnableJobs.APSIMPostSimulationJob(workingDirectory));
            if (spec.Paddock.Count > 0 && spec.Paddock[0].RunType != Paddock.RunTypeEnum.Validation)
                completeJob.Jobs.Add(new RunnableJobs.YPPostSimulationJob(jobName, spec.Paddock[0].NowDate, workingDirectory));

            return completeJob;
        }
Ejemplo n.º 8
0
    public static int[] JobSequencing(int[] profits, int[] deadlines)
    {
        JobSequence[] jobSequences = new JobSequence[deadlines.Length];

        for (int i = 0; i < deadlines.Length; i++)
        {
            jobSequences[i] = new JobSequence(profits[i], deadlines[i]);
        }
        int[] result  = new int[deadlines.Max()];
        var   compare = new Compare();

        Array.Sort(jobSequences, compare);
        int resultCapacity = 0;

        for (int i = 0; i < jobSequences.Length; i++)
        {
            int index = jobSequences[i].deadline - 1;
            if (result[index] <= 0)
            {
                result[index] = i + 1;
                resultCapacity++;
            }
            else
            {
                while (index > 0)
                {
                    index--;
                    if (result[index] == 0)
                    {
                        result[index] = i + 1;
                        resultCapacity++;
                        break;
                    }
                }
            }
            if (resultCapacity == result.Length)
            {
                break;
            }
        }
        return(result);
    }
Ejemplo n.º 9
0
 //public void AddJobItemTo(JobSequence jobSequence, JobItem jobItem)
 //{
 //    Check.Require(jobItem != null,
 //        "jobItem cannot be null", new ArgumentNullException("jobItem"));
 //    Check.Require(jobSequence != null,
 //        "jobSequence cannot be null", new ArgumentNullException("jobSequence"));
 //    JobItem[] items = jobSequence.JobItems;
 //    int length = items == null ? 0 : items.Length;
 //    Array.Resize(ref items, length + 1);
 //    jobSequence.JobItems[jobSequence.JobItems.Length] = jobItem;
 //}
 public DateTime NextSequencedJob(JobSequence jobSequence)
 {
     return DateTime.Now;
 }