Beispiel #1
0
 /// <summary>
 /// Constructor for scripted subsystems
 /// </summary>
 /// <param name="ADCSNode"></param>
 /// <param name="asset"></param>
 public ADCS(XmlNode ADCSNode, Asset asset)
 {
     Asset = asset;
     GetSubNameFromXmlNode(ADCSNode);
     POINTVEC_KEY = new StateVarKey<Matrix<double>>(Asset.Name + "." + "eci_pointing_vector(xyz)");
     addKey(POINTVEC_KEY);
 }
Beispiel #2
0
 /// <summary>
 /// Constructor for built in subsystem
 /// Defaults: lowQualityPixels = 5000, midQualityPixels = 10000, highQualityPixels = 15000
 /// lowQualityTime = 3s, midQyalityTime = 5s, highQualityTime = 7s
 /// </summary>
 /// <param name="EOSensorXmlNode"></param>
 /// <param name="dependencies"></param>
 /// <param name="asset"></param>
 public EOSensor(XmlNode EOSensorXmlNode, Dependency dependencies, Asset asset)
 {
     DefaultSubName = "EOSensor";
     Asset = asset;
     GetSubNameFromXmlNode(EOSensorXmlNode);
     PIXELS_KEY = new StateVarKey<double>(Asset.Name +"." + "numpixels");
     INCIDENCE_KEY = new StateVarKey<double>(Asset.Name + "." + "incidenceangle");
     EOON_KEY = new StateVarKey<bool>(Asset.Name + "." + "eosensoron");
     addKey(PIXELS_KEY);
     addKey(INCIDENCE_KEY);
     addKey(EOON_KEY);
     DependentSubsystems = new List<Subsystem>();
     SubsystemDependencyFunctions = new Dictionary<string, Delegate>();
     if (EOSensorXmlNode.Attributes["lowQualityPixels"] != null)
         _lowQualityPixels = (double)Convert.ChangeType(EOSensorXmlNode.Attributes["lowQualityPixels"].Value.ToString(), typeof(double));
     if (EOSensorXmlNode.Attributes["lowQualityPixels"] != null)
         _lowQualityTime = (double)Convert.ChangeType(EOSensorXmlNode.Attributes["lowQualityTime"].Value.ToString(), typeof(double));
     if (EOSensorXmlNode.Attributes["midQualityPixels"] != null)
         _midQualityPixels = (double)Convert.ChangeType(EOSensorXmlNode.Attributes["midQualityPixels"].Value.ToString(), typeof(double));
     if (EOSensorXmlNode.Attributes["midQualityTime"] != null)
         _midQualityTime = (double)Convert.ChangeType(EOSensorXmlNode.Attributes["midQualityTime"].Value.ToString(), typeof(double));
     if (EOSensorXmlNode.Attributes["highQualityPixels"] != null)
         _highQualityPixels = (double)Convert.ChangeType(EOSensorXmlNode.Attributes["highQualityPixels"].Value.ToString(), typeof(double));
     if (EOSensorXmlNode.Attributes["highQualityTime"] != null)
         _highQualityTime = (double)Convert.ChangeType(EOSensorXmlNode.Attributes["highQualityTime"].Value.ToString(), typeof(double));
     dependencies.Add("PowerfromEOSensor"+"."+Asset.Name, new Func<Event, HSFProfile<double>>(POWERSUB_PowerProfile_EOSENSORSUB));
     dependencies.Add("SSDRfromEOSensor" + "." + Asset.Name, new Func<Event, HSFProfile<double>>(SSDRSUB_NewDataProfile_EOSENSORSUB));
 }
Beispiel #3
0
 /// <summary>
 /// Constructor for the built in subsystem (cannot be scripted)
 /// </summary>
 /// <param name="subNode"></param>
 /// <param name="asset"></param>
 public AccessSub(XmlNode subNode, Asset asset)
 {
     Asset = asset;
     DefaultSubName = "AccessToTarget";
     GetSubNameFromXmlNode(subNode);
     DependentSubsystems = new List<Subsystem>();
     SubsystemDependencyFunctions = new Dictionary<string, Delegate>();
 }
Beispiel #4
0
 /// <summary>
 /// returns the last task in the schedule for a specific asset
 /// </summary>
 /// <returns></returns>
 public Task GetLastTask(Asset asset)
 {
     if (isEmpty() == false) //TODO: check that this is actually what we want to do.
     {
         return Events.Peek().GetAssetTask(asset);
     }
     else return null;
 }
Beispiel #5
0
 /// <summary>
 /// Constructor for scripted subsystem
 /// </summary>
 /// <param name="CommXmlNode"></param>
 /// <param name="asset"></param>
 public Comm(XmlNode CommXmlNode, Asset asset)
 {
     DefaultSubName = "Comm";
     Asset = asset;
     GetSubNameFromXmlNode(CommXmlNode);
     DATARATE_KEY = new StateVarKey<double>(Asset.Name + "." + "datarate(mb/s)");
     addKey(DATARATE_KEY);
 }
Beispiel #6
0
 /// <summary>
 /// Constructor for use by scripted subsystem
 /// </summary>
 /// <param name="SSDRXmlNode"></param>
 /// <param name="asset"></param>
 public SSDR(XmlNode SSDRXmlNode, Asset asset)
 {
     DefaultSubName = "SSDR";
     Asset = asset;
     GetSubNameFromXmlNode(SSDRXmlNode);
     if (SSDRXmlNode.Attributes["bufferSize"] != null)
         _bufferSize = (double)Convert.ChangeType(SSDRXmlNode.Attributes["bufferSize"].Value.ToString(), typeof(double));
     DATABUFFERRATIO_KEY = new StateVarKey<double>(Asset.Name + "." + "databufferfillratio");
     addKey(DATABUFFERRATIO_KEY);
 }
Beispiel #7
0
 /// <summary>
 /// Constructor for built in subsystem
 /// </summary>
 /// <param name="CommXmlNode"></param>
 /// <param name="dependencies"></param>
 /// <param name="asset"></param>
 public Comm(XmlNode CommXmlNode, Dependency dependencies, Asset asset)
 {
     DefaultSubName = "Comm";
     Asset = asset;
     GetSubNameFromXmlNode(CommXmlNode);
     SubsystemDependencyFunctions = new Dictionary<string, Delegate>();
     DependentSubsystems = new List<Subsystem>();
     DATARATE_KEY = new StateVarKey<double>(Asset.Name + "." + "datarate(mb/s)");
     addKey(DATARATE_KEY);
     dependencies.Add("PowerfromComm" + "." + Asset.Name, new Func<Event, HSFProfile<double>>(POWERSUB_PowerProfile_COMMSUB));
 }
Beispiel #8
0
 /// <summary>
 /// Constructor for built in subsystem
 /// Default: BufferSize = 4098
 /// </summary>
 /// <param name="SSDRXmlNode"></param>
 /// <param name="dependencies"></param>
 /// <param name="asset"></param>
 public SSDR(XmlNode SSDRXmlNode, Dependency dependencies, Asset asset)
 {
     DefaultSubName = "SSDR";
     Asset = asset;
     GetSubNameFromXmlNode(SSDRXmlNode);
     if (SSDRXmlNode.Attributes["bufferSize"] != null)
         _bufferSize = (double)Convert.ChangeType(SSDRXmlNode.Attributes["bufferSize"].Value.ToString(), typeof(double));
     DATABUFFERRATIO_KEY = new StateVarKey<double>(Asset.Name + "." +"databufferfillratio");
     addKey(DATABUFFERRATIO_KEY);
     SubsystemDependencyFunctions = new Dictionary<string, Delegate>();
     DependentSubsystems = new List<Subsystem>();
     dependencies.Add("PowerfromSSDR" + "." + Asset.Name, new Func<Event, HSFProfile<double>>(POWERSUB_PowerProfile_SSDRSUB));
     dependencies.Add("CommfromSSDR" + "." + Asset.Name, new Func<Event, HSFProfile<double>>(COMMSUB_DataRateProfile_SSDRSUB));
     dependencies.Add("EvalfromSSDR" + "." + Asset.Name, new Func<Event, double>(EVAL_DataRateProfile_SSDRSUB));
 }
Beispiel #9
0
 /// <summary>
 /// Constructor for built in subsystem
 /// </summary>
 /// <param name="PowerNode"></param>
 /// <param name="asset"></param>
 public Power(XmlNode PowerNode, Asset asset)
 {
     DefaultSubName = "Power";
     Asset = asset;
     GetSubNameFromXmlNode(PowerNode);
     DOD_KEY = new StateVarKey<double>(Asset.Name + "." + "depthofdischarge");
     POWIN_KEY = new StateVarKey<double>(Asset.Name + "." + "solarpanelpowerin");
     addKey(DOD_KEY);
     addKey(POWIN_KEY);
     if (PowerNode.Attributes["batterySize"] != null)
         _batterySize = (double)Convert.ChangeType(PowerNode.Attributes["batterySize"].Value, typeof(double));
     if (PowerNode.Attributes["fullSolarPower"] != null)
         _fullSolarPanelPower = (double)Convert.ChangeType(PowerNode.Attributes["fullSolarPower"].Value, typeof(double));
     if (PowerNode.Attributes["penumbraSolarPower"] != null)
         _penumbraSolarPanelPower = (double)Convert.ChangeType(PowerNode.Attributes["penumbraSolarPower"].Value, typeof(double));
 }
Beispiel #10
0
 /// <summary>
 /// Constructor for built in subsystems
 /// Defaults: Slew time: 10s
 /// </summary>
 /// <param name="ADCSNode"></param>
 /// <param name="dependencies"></param>
 /// <param name="asset"></param>
 public ADCS(XmlNode ADCSNode, Dependency dependencies, Asset asset) 
 {
     DefaultSubName = "Adcs";
     Asset = asset;
     GetSubNameFromXmlNode(ADCSNode);
     /*double slewTime;
     if (ADCSNode.Attributes["timetoslew"].Value != null)
     {
         Double.TryParse(ADCSNode.Attributes["slewTime"].Value, out slewTime);
         _timetoslew = slewTime;
     }*/
     POINTVEC_KEY = new StateVarKey<Matrix<double>>(Asset.Name + "." + "eci_pointing_vector(xyz)");
     addKey(POINTVEC_KEY);
     DependentSubsystems = new List<Subsystem>();
     SubsystemDependencyFunctions = new Dictionary<string, Delegate>();
     dependencies.Add("PowerfromADCS"+"."+Asset.Name, new Func<Event, HSFProfile<double>>(POWERSUB_PowerProfile_ADCSSUB));
 }
Beispiel #11
0
 /// <summary>
 /// A method to interpret the Xml file and create subsystems
 /// </summary>
 /// <param name="SubsystemXmlNode"></param>
 /// <param name="enableScripting"></param>
 /// <param name="dependencies"></param>
 /// <param name="asset"></param>
 /// <param name="subDic"></param>
 /// <returns></returns>
 public static string GetSubsystem(XmlNode SubsystemXmlNode, Dependency dependencies, Asset asset, Dictionary<string, Subsystem> subDic)
 {
     string type = SubsystemXmlNode.Attributes["Type"].Value.ToString().ToLower();
     string name = Subsystem.parseNameFromXmlNode(SubsystemXmlNode, asset.Name);
     if (type.Equals("scripted"))
     {
         subDic.Add(name, new ScriptedSubsystem(SubsystemXmlNode, dependencies, asset));
     }
     else // not scripted subsystem
     {
         if (type.Equals("access"))
         {
             subDic.Add(name, new AccessSub(SubsystemXmlNode, asset));
         }
         else if (type.Equals("adcs"))
         {
            subDic.Add(name, new ADCS(SubsystemXmlNode, dependencies, asset));
         }
         else if (type.Equals("power"))
         {
             subDic.Add(name, new Power(SubsystemXmlNode, dependencies, asset));
         }
         else if (type.Equals("eosensor"))
         {
             subDic.Add(name, new EOSensor(SubsystemXmlNode, dependencies, asset));
         }
         else if (type.Equals("ssdr"))
         {
             subDic.Add(name, new SSDR(SubsystemXmlNode, dependencies, asset));
         }
         else if (type.Equals("comm"))
         {
             subDic.Add(name, new Comm(SubsystemXmlNode, dependencies, asset));
         }
         else if (type.Equals("networked"))
         {
             throw new NotImplementedException("Networked Subsystem is a depreciated feature!");
         }
         else
         {
             log.Fatal("Horizon does not recognize the subsystem: " + type);
             throw new MissingMemberException("Unknown Subsystem Type " + type);
         }
     }
     return name;
 }
Beispiel #12
0
 /// <summary>
 /// Constructor for built in subsystem
 /// Defaults: batterySize = 1000000, fullSolarPanelPower =150, penumbraSolarPanelPower = 75
 /// </summary>
 /// <param name="PowerNode"></param>
 /// <param name="dependencies"></param>
 public Power(XmlNode PowerNode, Dependency dependencies, Asset asset) 
 {
     DefaultSubName = "Power";
     Asset = asset;
     GetSubNameFromXmlNode(PowerNode);
     DOD_KEY = new StateVarKey<double>(Asset.Name + "." + "depthofdischarge");
     POWIN_KEY = new StateVarKey<double>(Asset.Name + "." + "solarpanelpowerin");
     addKey(DOD_KEY);
     addKey(POWIN_KEY);
     SubsystemDependencyFunctions = new Dictionary<string, Delegate>();
     DependentSubsystems = new List<Subsystem>();
     if (PowerNode.Attributes["batterySize"] != null)
         _batterySize = (double)Convert.ChangeType(PowerNode.Attributes["batterySize"].Value, typeof(double));
     if (PowerNode.Attributes["fullSolarPower"] != null)
         _fullSolarPanelPower = (double)Convert.ChangeType(PowerNode.Attributes["fullSolarPower"].Value, typeof(double));
     if(PowerNode.Attributes["penumbraSolarPower"] != null)
         _penumbraSolarPanelPower = (double)Convert.ChangeType(PowerNode.Attributes["penumbraSolarPower"].Value, typeof(double));
 }
Beispiel #13
0
        /// <summary>
        /// Constructor to initialize the python subsystem
        /// </summary>
        /// <param name="scriptedSubXmlNode"></param>
        /// <param name="dependencies"></param>
        /// <param name="asset"></param>
        public ScriptedSubsystem(XmlNode scriptedSubXmlNode, Dependency dependencies, Asset asset)
        {
            Asset = asset;
            GetSubNameFromXmlNode(scriptedSubXmlNode);
            string pythonFilePath ="", className = "";
            XmlParser.ParseScriptedSrc(scriptedSubXmlNode, ref pythonFilePath, ref className);

            var engine = Python.CreateEngine();
            var scope = engine.CreateScope();
            var ops = engine.Operations;
            engine.ExecuteFile(pythonFilePath, scope);
            var pythonType = scope.GetVariable(className);
            _pythonInstance = ops.CreateInstance(pythonType, scriptedSubXmlNode, asset);
            Dictionary<string, Delegate> newDependencies = _pythonInstance.GetDependencyDictionary();
            dependencies.Append(newDependencies);
            DependentSubsystems = new List<Subsystem>();
            SubsystemDependencyFunctions = new Dictionary<string, Delegate>();
            Delegate depCollector = _pythonInstance.GetDependencyCollector();
            SubsystemDependencyFunctions.Add("DepCollector", depCollector);
        }
Beispiel #14
0
        /// <summary>
        /// Constraint generator to translate XML nodes to actual constraints
        /// </summary>
        /// <param name="constraintXmlNode"></param>
        /// <param name="subsystemMap"></param>
        /// <param name="asset"></param>
        /// <returns></returns>
        public static Constraint GetConstraint(XmlNode constraintXmlNode, Dictionary<string, Subsystem> subsystemMap, Asset asset)
        {
            Subsystem constrainedSub = null;
            string subName = Subsystem.parseNameFromXmlNode(constraintXmlNode, asset.Name);
            subsystemMap.TryGetValue(subName, out constrainedSub);
            if (constrainedSub == null)
                throw new MissingMemberException("Missing Subsystem Name in Constraint");

            string type = constraintXmlNode["STATEVAR"].Attributes["type"].Value.ToLower();

            if (type.Equals("int"))
                return new SingleConstraint<int>(constraintXmlNode, constrainedSub);
            else if (type.Equals("double"))
                return new SingleConstraint<double>(constraintXmlNode, constrainedSub);
            else if (type.Equals("bool"))
                return new SingleConstraint<bool>(constraintXmlNode, constrainedSub);
            else if (type.Equals("Matrix"))
                return new SingleConstraint<Matrix<double>>(constraintXmlNode,constrainedSub);
            else //TODO: Add functionality to create scripted constraints
                throw new NotSupportedException("Unsupported type of constraint!");

            
        }
Beispiel #15
0
 /// <summary>
 /// Constructor for scripted subsystem
 /// </summary>
 /// <param name="EOSensorXmlNode"></param>
 /// <param name="asset"></param>
 public EOSensor(XmlNode EOSensorXmlNode, Asset asset)
 {
     DefaultSubName = "EOSensor";
     Asset = asset;
     GetSubNameFromXmlNode(EOSensorXmlNode);
     PIXELS_KEY = new StateVarKey<double>(Asset.Name + "." + "numpixels");
     INCIDENCE_KEY = new StateVarKey<double>(Asset.Name + "." + "incidenceangle");
     EOON_KEY = new StateVarKey<bool>(Asset.Name + "." + "eosensoron");
     addKey(PIXELS_KEY);
     addKey(INCIDENCE_KEY);
     addKey(EOON_KEY);
     if (EOSensorXmlNode.Attributes["lowQualityPixels"] != null)
         _lowQualityPixels = (double)Convert.ChangeType(EOSensorXmlNode.Attributes["lowQualityPixels"].Value.ToString(), typeof(double));
     if (EOSensorXmlNode.Attributes["lowQualityPixels"] != null)
         _lowQualityTime = (double)Convert.ChangeType(EOSensorXmlNode.Attributes["lowQualityTime"].Value.ToString(), typeof(double));
     if (EOSensorXmlNode.Attributes["midQualityPixels"] != null)
         _midQualityPixels = (double)Convert.ChangeType(EOSensorXmlNode.Attributes["midQualityPixels"].Value.ToString(), typeof(double));
     if (EOSensorXmlNode.Attributes["midQualityTime"] != null)
         _midQualityTime = (double)Convert.ChangeType(EOSensorXmlNode.Attributes["midQualityTime"].Value.ToString(), typeof(double));
     if (EOSensorXmlNode.Attributes["highQualityPixels"] != null)
         _highQualityPixels = (double)Convert.ChangeType(EOSensorXmlNode.Attributes["highQualityPixels"].Value.ToString(), typeof(double));
     if (EOSensorXmlNode.Attributes["highQualityTime"] != null)
         _highQualityTime = (double)Convert.ChangeType(EOSensorXmlNode.Attributes["highQualityTime"].Value.ToString(), typeof(double));
 }
Beispiel #16
0
 public double GetEventEnd(Asset asset)
 {
     double time;
     EventEnds.TryGetValue(asset, out time);
     return time;
 }
Beispiel #17
0
        static int Main(string[] args)
        {
            // Begin the Logger
            ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            log.Info("STARTING HSF RUN"); //Do not delete

            // Set Defaults
            var simulationInputFilePath = @"..\..\..\SimulationInput.XML";
            var targetDeckFilePath = @"..\..\..\v2.2-300targets.xml";
            var modelInputFilePath = @"..\..\..\DSAC_Static.xml";
            bool simulationSet = false, targetSet = false, modelSet = false;

            // Get the input filenames
            int i = 0;
            foreach(var input in args)
            {
                i++;
                switch (input)
                {
                    case "-s":
                        simulationInputFilePath = args[i];
                        simulationSet = true;
                        break;
                    case "-t":
                        targetDeckFilePath = args[i];
                        targetSet = true;
                        break;
                    case "-m":
                        modelInputFilePath = args[i];
                        modelSet = true;
                        break;
                }
            }
            ///add usage statement

            if (!simulationSet)
            {
                log.Info("Using Default Simulation File");
            }

            if (!targetSet)
            {
                log.Info("Using Default Target File");
            }

            if (!modelSet)
            {
                log.Info("Using Default Model File");
            }


            // Initialize Output File
            var outputFileName = string.Format("output-{0:yyyy-MM-dd}-*", DateTime.Now);
            var outputPath = @"C:\HorizonLog\";
            var txt = ".txt";
            string[] fileNames = System.IO.Directory.GetFiles(outputPath, outputFileName, System.IO.SearchOption.TopDirectoryOnly);
            double number = 0;
            foreach (var fileName in fileNames)
            {
                char version = fileName[fileName.Length - txt.Length-1];
                if(number < Char.GetNumericValue(version))
                    number = Char.GetNumericValue(version);
            }
            number++;
            outputFileName = outputFileName.Remove(outputFileName.Length - 1) + number;
            outputPath += outputFileName + txt;
            // Find the main input node from the XML input files
            XmlNode evaluatorNode = XmlParser.ParseSimulationInput(simulationInputFilePath);

            // Load the target deck into the targets list from the XML target deck input file
            Stack<Task> systemTasks = new Stack<Task>();
            bool targetsLoaded = Task.loadTargetsIntoTaskList(XmlParser.GetTargetNode(targetDeckFilePath), systemTasks);
            if (!targetsLoaded)
            {
                return 1;
            }

            // Find the main model node from the XML model input file
            var modelInputXMLNode = XmlParser.GetModelNode(modelInputFilePath);

            // Load the environment. First check if there is an ENVIRONMENT XMLNode in the input file
            Universe SystemUniverse = null;

            //Create singleton dependency dictionary
            Dependency dependencies = Dependency.Instance;

            // Initialize List to hold assets and subsystem nodes
            List<Asset> assetList = new List<Asset>();
            List<Subsystem> subList = new List<Subsystem>();

            // Maps used to set up preceeding nodes
            Dictionary<ISubsystem, XmlNode> subsystemXMLNodeMap = new Dictionary<ISubsystem, XmlNode>();
            Dictionary<string, Subsystem> subsystemMap = new Dictionary<string, Subsystem>();
            List<KeyValuePair<string, string>> dependencyMap = new List<KeyValuePair<string, string>>();
            List<KeyValuePair<string, string>> dependencyFcnMap = new List<KeyValuePair<string, string>>();
            // Dictionary<string, ScriptedSubsystem> scriptedSubNames = new Dictionary<string, ScriptedSubsystem>();

            // Create Constraint list 
            List<Constraint> constraintsList = new List<Constraint>();

            //Create Lists to hold all the initial condition and dependency nodes to be parsed later
            List<XmlNode> ICNodes = new List<XmlNode>();
            List<XmlNode> DepNodes = new List<XmlNode>();
            SystemState initialSysState = new SystemState();

            // Set up Subsystem Nodes, first loop through the assets in the XML model input file
            foreach (XmlNode modelChildNode in modelInputXMLNode.ChildNodes)
            {
                if (modelChildNode.Name.Equals("ENVIRONMENT"))
                {
                    // Create the Environment based on the XMLNode
                    SystemUniverse = new Universe(modelChildNode);
                }
                if (modelChildNode.Name.Equals("ASSET"))
                {
                    Asset asset = new Asset(modelChildNode);
                    assetList.Add(asset);
                    // Loop through all the of the ChildNodess for this Asset
                    foreach (XmlNode childNode in modelChildNode.ChildNodes)
                    {
                        // Get the current Subsystem XML Node, and create it using the SubsystemFactory
                        if (childNode.Name.Equals("SUBSYSTEM"))
                        {  //is this how we want to do this?
                            // Check if the type of the Subsystem is scripted, networked, or other
                            string subName = SubsystemFactory.GetSubsystem(childNode, dependencies, asset, subsystemMap);
                            foreach (XmlNode ICorDepNode in childNode.ChildNodes)
                            {
                                if(ICorDepNode.Name.Equals("IC"))
                                    ICNodes.Add(ICorDepNode);
                                if (ICorDepNode.Name.Equals("DEPENDENCY"))
                                {
                                    string depSubName = "", depFunc = "";
                                    depSubName = Subsystem.parseNameFromXmlNode(ICorDepNode, asset.Name) ;
                                    dependencyMap.Add(new KeyValuePair<string, string>(subName, depSubName));

                                    if (ICorDepNode.Attributes["fcnName"] != null)
                                    {
                                        depFunc = ICorDepNode.Attributes["fcnName"].Value.ToString();
                                        dependencyFcnMap.Add(new KeyValuePair<string, string>(subName, depFunc));
                                    }
                                }  
                            }
                        }
                        //Create a new Constraint
                        if (childNode.Name.Equals("CONSTRAINT"))
                        {
                            constraintsList.Add(ConstraintFactory.GetConstraint(childNode, subsystemMap, asset));
                        }
                    }
                    if (ICNodes.Count > 0)
                        initialSysState.Add(SystemState.setInitialSystemState(ICNodes, asset));
                    ICNodes.Clear();
                }
            }
            if (SystemUniverse == null)
                SystemUniverse = new Universe();

            foreach (KeyValuePair<string, Subsystem> sub in subsystemMap)
            {
                if(!sub.Value.GetType().Equals(typeof(ScriptedSubsystem)))//let the scripted subsystems add their own dependency collector
                    sub.Value.AddDependencyCollector();
                subList.Add(sub.Value);
            }
            log.Info("Subsystems and Constraints Loaded");

            //Add all the dependent subsystems to the dependent subsystem list of the subsystems
            foreach (KeyValuePair<string, string> depSubPair in dependencyMap)
            {
                Subsystem subToAddDep, depSub;
                subsystemMap.TryGetValue(depSubPair.Key, out subToAddDep);
                subsystemMap.TryGetValue(depSubPair.Value, out depSub);
                subToAddDep.DependentSubsystems.Add(depSub);
            }

            //give the dependency functions to all the subsytems that need them
            foreach (KeyValuePair<string, string> depFunc in dependencyFcnMap)
            {
                Subsystem subToAddDep;
                subsystemMap.TryGetValue(depFunc.Key, out subToAddDep);
                subToAddDep.SubsystemDependencyFunctions.Add(depFunc.Value, dependencies.GetDependencyFunc(depFunc.Value));
            }
            log.Info("Dependencies Loaded");

            SystemClass simSystem = new SystemClass(assetList, subList, constraintsList, SystemUniverse);

            if (simSystem.CheckForCircularDependencies())
                throw new NotFiniteNumberException("System has circular dependencies! Please correct then try again.");

            Evaluator schedEvaluator = EvaluatorFactory.GetEvaluator(evaluatorNode, dependencies);
            Scheduler scheduler = new Scheduler(schedEvaluator);
            List<SystemSchedule> schedules = scheduler.GenerateSchedules(simSystem, systemTasks, initialSysState);
            // Evaluate the schedules and set their values
            foreach (SystemSchedule systemSchedule in schedules)
            {
                systemSchedule.ScheduleValue = schedEvaluator.Evaluate(systemSchedule);
                bool canExtendUntilEnd = true;
                // Extend the subsystem states to the end of the simulation 
                foreach (var subsystem in simSystem.Subsystems)
                {
                    if(systemSchedule.AllStates.Events.Count >0)
                        if (!subsystem.CanExtend(systemSchedule.AllStates.Events.Peek(), simSystem.Environment, SimParameters.SimEndSeconds))
                            log.Error("Cannot Extend " + subsystem.Name + " to end of simulation");
                }
            }

            // Sort the sysScheds by their values
            schedules.Sort((x, y) => x.ScheduleValue.CompareTo(y.ScheduleValue));
            schedules.Reverse();
            double maxSched = schedules[0].ScheduleValue;
            i = 0;
            //Morgan's Way
            using (StreamWriter sw = File.CreateText(outputPath))
            {
                foreach (SystemSchedule sched in schedules)
                {
                    sw.WriteLine("Schedule Number: " + i + "Schedule Value: " + schedules[i].ScheduleValue);
                    foreach (var eit in sched.AllStates.Events)
                    {
                        if (i < 5)//just compare the first 5 schedules for now
                        { 
                            sw.WriteLine(eit.ToString());
                        }
                    }
                    i++;
            }
            log.Info("Max Schedule Value: " + maxSched);
            }

            // Mehiel's way
            string stateDataFilePath = @"C:\HorizonLog\" + string.Format("output-{0:yyyy-MM-dd-hh-mm-ss}", DateTime.Now);
            SystemSchedule.WriteSchedule(schedules[0], stateDataFilePath);

            var csv = new StringBuilder();
            csv.Clear();
            foreach (var asset in simSystem.Assets)
            {
                File.WriteAllText(@"..\..\..\" + asset.Name + "_dynamicStateData.csv", asset.AssetDynamicState.ToString());
            }
            return 0;
            //   Console.ReadKey();
        }
Beispiel #18
0
        public Subsystem(XmlNode xmlNode, Dependency deps, Asset asset)
        {

        }
Beispiel #19
0
        public Subsystem(XmlNode xmlNode, Asset asset)
        {

        }
Beispiel #20
0
 /// <summary>
 /// Returns true if the specified asset doesn't have a task (the asset isn't scheduled)
 /// </summary>
 /// <returns></returns>
 public bool isEmpty(Asset asset)
 {
     foreach(Event eit in Events)
     {
         if (eit.Tasks.ContainsKey(asset)) //something has been scheduled
             return false;
     }
     return true;
 }
Beispiel #21
0
 /// <summary>
 /// Returns the number of events in the schedule for a specific asset
 /// </summary>
 /// <param name="asset"></param>
 /// <returns></returns>
 public int size(Asset asset)
 {
     int count = 0;
     foreach (Event eit in Events)
     {
         if (eit.Tasks.ContainsKey(asset))
             count++;
     }
     return count;
 }
Beispiel #22
0
 /// <summary>
 /// Returns the number of times the specified task has been completed in this schedule for a specific asset
 /// </summary>
 /// <param name="task"></param>
 /// <returns></returns>
 public int timesCompletedTask(Asset asset, Task task)
 {
     int count = 0;
     KeyValuePair<Asset, Task> search = new KeyValuePair<Asset, Task>(asset, task);
     foreach(Event eit in Events)
     {
         foreach(KeyValuePair<Asset, Task> pair in eit.Tasks)
         {
             if (pair.Equals(search))
                 count++;
         }
     }
     return count;
 }
Beispiel #23
0
 /// <summary>
 /// Get the current task assigned to the asset
 /// </summary>
 /// <param name="asset"></param>
 /// <returns></returns>
 public Task GetAssetTask(Asset asset)
 {
     Task currentTask;
     Tasks.TryGetValue(asset, out currentTask);
     return currentTask;
 }
Beispiel #24
0
 public void SetEventStart(Asset asset, double te)
 {
     if (EventEnds.ContainsKey(asset))
         EventEnds.Remove(asset);
     EventEnds.Add(asset, te);
 }
Beispiel #25
0
 public void SetTaskStart(Asset asset, double te)
 {
     if (TaskStarts.ContainsKey(asset))
         TaskStarts.Remove(asset);
     TaskStarts.Add(asset, te);
 }
Beispiel #26
0
 public Access(Asset asset, Task task)
 {
     Asset = asset;
     Task = task;
 }
Beispiel #27
0
 public double GetTaskStart(Asset asset)
 {
     double time;
     TaskStarts.TryGetValue(asset, out time);
     return time;
 }
Beispiel #28
0
 /// <summary>
 /// Find all accesses available to an asset at the current time
 /// </summary>
 /// <param name="accesses"></param>
 /// <param name="asset"></param>
 /// <param name="currentTime"></param>
 /// <returns></returns>
 public static Stack<Access> getCurrentAccessesForAsset(Stack<Access> accesses, Asset asset, double currentTime)
 {
     Stack<Access> allAccesses = Access.getCurrentAccesses(accesses, currentTime);
     return new Stack<Access>(allAccesses.Where(item => item.Asset == asset));
 }