private void RunInitial(string cimPath, string cosemPath, string subStandardPath, int index = 0) { var needSubstandard = transformationName == OutagePrevention; var stopwatch = new Stopwatch(); stopwatch.Start(); cim = repository.Resolve(cimPath).RootElements[0] as CIM.CIMRoot; cosem = repository.Resolve(cosemPath).RootElements[0] as COSEM.COSEMRoot; substation = needSubstandard ? repository.Resolve(subStandardPath).RootElements[0] as SubstationStandard.Substandard : null; stopwatch.Stop(); if (index == 0) { Emit(stopwatch, "Loading"); } if (needSubstandard) { var triple = new Tuple <CIM.CIMRoot, COSEM.COSEMRoot, SubstationStandard.Substandard>(cim, cosem, substation); Model result = null; var outagePrevention = new OutagePrevention(); outagePrevention.Initialize(); stopwatch.Restart(); outagePrevention.Synchronize(outagePrevention.SynchronizationRule <OutagePrevention.MainRule>(), ref triple, ref result, SynchronizationDirection.LeftToRight, NMF.Transformations.ChangePropagationMode.OneWay); stopwatch.Stop(); elementCount = () => result.RootElements.Count; } else { var tuple = new Tuple <CIM.CIMRoot, COSEM.COSEMRoot>(cim, cosem); Model result = null; var outageDetection = new OutageDetection(); outageDetection.Initialize(); stopwatch.Restart(); outageDetection.Synchronize(outageDetection.SynchronizationRule <OutageDetection.MainRule>(), ref tuple, ref result, SynchronizationDirection.LeftToRight, NMF.Transformations.ChangePropagationMode.OneWay); stopwatch.Stop(); elementCount = () => result.RootElements.Count; } if (index == 0) { Emit(stopwatch, "Initial"); } else { Emit(stopwatch, "Update", index); } }
internal void GenerateChanges(Options options) { Console.WriteLine("Initializing repository"); var repository = new ModelRepository(); Console.WriteLine("Loading CIM model"); cim = repository.Resolve(options.CimPath).RootElements[0] as CIM.CIMRoot; Console.WriteLine("Loading COSEM model"); cosem = repository.Resolve(options.CosemPath).RootElements[0] as COSEM.COSEMRoot; Console.WriteLine("Loading Substandard model"); substation = repository.Resolve(options.SubstationPath).RootElements[0] as SubstationStandard.Substandard; Console.WriteLine("Performing changes"); var actions = new Action[] { ToggleRandomConnection, IncreaseRandomElectricityValues, CreateNewMeterAsset, DeleteMeterAsset, IncreaseMMXUVoltage, CreateMMXU, ChangeMMXULocation, ChangePosition }; var probabilities = new int[] { 10, 30, 10, 10, 20, 10, 5, 5 }; var sum = probabilities.Sum(); CreateDirectory(options.CimOutPath); CreateDirectory(options.CosemOutPath); CreateDirectory(options.SubstationOutPath); Console.WriteLine("Saving modified CIM model"); var cimPath = options.CimOutPath + string.Format("-out{0:000}.xmi", 0); repository.Save(cim, cimPath); cim.Model.ModelUri = new Uri(Path.GetFullPath(cimPath)); Console.WriteLine("Saving modified COSEM model"); var cosemPath = options.CosemOutPath + string.Format("-out{0:000}.xmi", 0); repository.Save(cosem, cosemPath); cosem.Model.ModelUri = new Uri(Path.GetFullPath(cosemPath)); Console.WriteLine("Saving modified Substandard model"); var subStandardPath = options.SubstationOutPath + string.Format("-out{0:000}.xmi", 0); repository.Save(substation, subStandardPath); substation.Model.ModelUri = new Uri(Path.GetFullPath(subStandardPath)); for (int d = 1; d <= options.Deltas; d++) { var cimRecorder = new ModelChangeRecorder(); var cosemRecorder = new ModelChangeRecorder(); var substationRecorder = new ModelChangeRecorder(); cimRecorder.Start(cim); cosemRecorder.Start(cosem); substationRecorder.Start(substation); Console.WriteLine($"Generating change {d}"); for (int i = 0; i < options.Changes; i++) { var dice = rnd.Next(sum); for (int j = 0; j < actions.Length; j++) { if (dice < probabilities[j]) { actions[j](); break; } else { dice -= probabilities[j]; } } } cimRecorder.Stop(); cosemRecorder.Stop(); substationRecorder.Stop(); Console.WriteLine("Saving modified CIM model"); repository.Serializer.Serialize(cim, options.CimOutPath + string.Format("-out{0:000}.xmi", d)); Console.WriteLine("Saving modified COSEM model"); repository.Serializer.Serialize(cosem, options.CosemOutPath + string.Format("-out{0:000}.xmi", d)); Console.WriteLine("Saving modified Substandard model"); repository.Serializer.Serialize(substation, options.SubstationOutPath + string.Format("-out{0:000}.xmi", d)); Console.WriteLine("Saving CIM changes"); repository.Save(cimRecorder.GetModelChanges(), options.CimOutPath + string.Format("-delta{0:000}.xmi", d)); Console.WriteLine("Saving COSEM changes"); repository.Save(cosemRecorder.GetModelChanges(), options.CosemOutPath + string.Format("-delta{0:000}.xmi", d)); Console.WriteLine("Saving Substandard changes"); repository.Save(substationRecorder.GetModelChanges(), options.SubstationOutPath + string.Format("-delta{0:000}.xmi", d)); } }