public VariableEvaluator(IEnumerable <VariableType> variables, oval_system_characteristics systemCharacteristics, oval_variables externalVariables) { this.variablesOfDefinitions = variables; this.evaluatorFactory = new EvaluatorFactory(); this.systemCharacteristics = systemCharacteristics; this.externalVariables = externalVariables; }
public IResultSummary Process(Resource resource, object fixture) { var specification = SpecificationReader.ReadSpecification(resource); var resultRecorder = new SummarizingResultRecorder(); specification.Process(EvaluatorFactory.CreateEvaluator(fixture), resultRecorder); return(resultRecorder); }
public static Solution Solve(IEnumerable <MenuOrder> menuOrders, IEnumerable <Worker> workers) { ProblemInstance instance = GetInstance(menuOrders, workers); Evaluator evaluator = EvaluatorFactory.getMakespanEvaluator(); Optimizer optimizer = OptimizerFactory.getPSOOptimizer(); //粒子群优化器,可以调用其他的 return(optimizer.minimize(instance, evaluator)); }
public MainWindow() { InitializeComponent(); EvaluatorFactory factory = new EvaluatorFactory(); foreach (string type in factory.types) { cbxType.Items.Add(factory[type]); } cbxType.SelectedIndex = 0; }
public void CreateSchedules(Stack <Task> systemTasks) { simSystem = new SystemClass(assetList, subList, constraintsList, SystemUniverse); if (simSystem.CheckForCircularDependencies()) { throw new NotFiniteNumberException("System has circular dependencies! Please correct then try again."); } schedEvaluator = EvaluatorFactory.GetEvaluator(evaluatorNode, dependencies); Scheduler scheduler = new Scheduler(schedEvaluator); schedules = scheduler.GenerateSchedules(simSystem, systemTasks, initialSysState); }
protected override void SpecificBuild() { var ctrXml = ConstraintXml as UniqueRowsXml; var builder = new SettingsEvaluatorBuilder(); builder.Setup(ctrXml.KeysSet, ctrXml.ValuesSet); builder.Setup(ctrXml.Columns); builder.Build(); var ctr = new UniqueRowsConstraint(); var settings = builder.GetSettings(); var factory = new EvaluatorFactory(); var evaluator = factory.Instantiate(settings); Constraint = ctr.Using(evaluator); }
public IAlternateBranch CreateAlternateBranch(IProcessExecutionContext executionContext, IRecordPointer <Guid> alternateBranchId, string name, int evaluationOrder, IRecordPointer <Guid> parentStepId, IRecordPointer <Guid> subsequentStepId, IRecordPointer <Guid> evaluatorTypeId, string parameters, bool useCache = true) { try { useCache = useCache && executionContext.Cache != null; string cacheKey = null; if (useCache) { cacheKey = CACHE_KEY + alternateBranchId.ToString(); if (executionContext.Cache.Exists(cacheKey)) { return(executionContext.Cache.Get <IAlternateBranch>(cacheKey)); } } if (evaluatorTypeId is null) { throw new ArgumentNullException("evaluatorTypeId"); } var evaluatorType = EvaluatorTypeFactory.BuildEvaluatorType(executionContext, evaluatorTypeId, useCache); var evaluator = EvaluatorFactory.CreateEvaluator(executionContext, alternateBranchId, evaluatorType, parameters, useCache); var alternateBranch = new AlternateBranch(alternateBranchId.RecordType, alternateBranchId.Id, name, evaluationOrder, parentStepId, subsequentStepId, evaluator); if (useCache) { var settings = SettingsFactory.CreateSettings(executionContext.Settings); var cacheTimeout = settings.AlternateBranchCacheTimeout; executionContext.Cache.Add <IAlternateBranch>(cacheKey, alternateBranch, cacheTimeout.Value); } return(alternateBranch); } catch (Exception) { throw; } }
/// <summary> /// Start a new business object instance /// </summary> /// <returns>Change the index id of the business object</returns> public static int CreateBussinessObjectInstance() { try { var scxml = RestaurantViewModel.GetEntryPointSCXML(); Evaluator ev = EvaluatorFactory.getEvaluator(scxml); SCXMLExecutor executor = new SCXMLExecutor(ev, new MulitStateMachineDispatcher(), new SimpleErrorReporter()); executor.setStateMachine(scxml); RestaurantViewModel.engineBridge.SetExecutorReference(RestaurantViewModel.executorCounter.ToString(), executor); RestaurantViewModel.executorDict[RestaurantViewModel.executorCounter] = executor; return(RestaurantViewModel.executorCounter++); } catch (Exception e) { lock (GlobalDataContext.ConsolePrintMutex) { Console.WriteLine(e.ToString()); } throw new ModelException(); } }
public IRequirement CreateRequirement(IProcessExecutionContext executionContext, IRecordPointer <Guid> requirementId, string name, eRequirementTypeFlags?requirementType, IRecordPointer <Guid> transactionTypeId, ILogicEvaluatorType evaluatorType, string parameters, IEnumerable <IRecordPointer <Guid> > waiverRoles, bool useCache = true) { try { useCache = useCache && executionContext.Cache != null; string cacheKey = null; if (useCache) { cacheKey = CACHE_KEY + requirementId.ToString(); if (executionContext.Cache.Exists(cacheKey)) { return(executionContext.Cache.Get <IRequirement>(cacheKey)); } } var evaluator = EvaluatorFactory.CreateEvaluator(executionContext, requirementId, evaluatorType, parameters, useCache); var requirement = new Requirement(requirementId.RecordType, requirementId.Id, name, requirementType, transactionTypeId, evaluator, waiverRoles); if (useCache) { var settings = SettingsFactory.CreateSettings(executionContext.Settings); var cacheTimeout = settings.TransactionRequirementCacheTimeout; executionContext.Cache.Add <IRequirement>(cacheKey, requirement, cacheTimeout.Value); } return(requirement); } catch (Exception) { throw; } }
/// <summary> /// Gets an evaluator delegate for the specified unary <paramref name="expression"/>. /// </summary> /// <param name="expression">The unary expression to get an evaluator delegate for.</param> /// <returns>A delegate that takes an <see cref="object"/> operand and returns an <see cref="object"/> result.</returns> protected virtual Func <object, object> GetEvaluator(UnaryExpression expression) => EvaluatorFactory.GetEvaluator(expression);
/// <summary> /// Gets an evaluator delegate for the specified (pure) <paramref name="member"/>. /// </summary> /// <param name="member">The member to get an evaluator delegate for.</param> /// <returns>A delegate that takes zero or more <see cref="object"/> parameters and returns either <see cref="object"/> or <see cref="void"/>.</returns> protected virtual Delegate GetEvaluator(MemberInfo member) => EvaluatorFactory.GetEvaluator(member);
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(); }
public MainViewModel() { _dataProviderFactory = new DataProviderFactory(Constants.DataFromWareHouse, Constants.WareHouseProjectPath, Constants.RepositoryPath); _evaluatorFactory = new EvaluatorFactory(Constants.EvaluationDataFromWareHouse, Constants.WareHouseProjectPath); _wareHouseWriter = new WareHouseWriter(Constants.WareHousePath, Constants.WareHouseProjectName); }