Skip to content

Commit

Permalink
Fixes #702 pi feedback (#703)
Browse files Browse the repository at this point in the history
* Fixes #702 pi feedback

* Fixes #702 pi feedback
  • Loading branch information
msevestre authored Jan 24, 2020
2 parents 8005f80 + b59333e commit 3d13a12
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ init:

environment:
app_version: '9.0'
APPVEYOR_BLOCK_DOTNETCORE_TESTS_AUTORUN: true

version: '$(app_version).{build}'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
using System.Threading;
using System.Threading.Tasks;
using OSPSuite.Assets;
using OSPSuite.Utility;
using OSPSuite.Utility.Collections;
using OSPSuite.Utility.Extensions;
using OSPSuite.Core.Domain.Mappers;
using OSPSuite.Core.Domain.ParameterIdentifications;
using OSPSuite.Core.Domain.ParameterIdentifications.Algorithms;
using OSPSuite.Utility;
using OSPSuite.Utility.Collections;
using OSPSuite.Utility.Extensions;

namespace OSPSuite.Core.Domain.Services.ParameterIdentifications
{
Expand Down Expand Up @@ -105,7 +105,7 @@ private void initializeParameterHistoryCache()
private ISimModelBatch createSimModelBatch(ISimulation simulation)
{
var simModelBatch = _simModelBatchFactory.Create();
var modelCoreSimulation = _modelCoreSimulationMapper.MapFrom(simulation, shouldCloneModel:true);
var modelCoreSimulation = _modelCoreSimulationMapper.MapFrom(simulation, shouldCloneModel: true);
_timeGridUpdater.UpdateSimulationTimeGrid(modelCoreSimulation, _parameterIdentification.Configuration.RemoveLLOQMode, _parameterIdentification.AllDataRepositoryMappedFor(simulation));
_outputSelectionUpdater.UpdateOutputsIn(modelCoreSimulation, _parameterIdentification.AllOutputsMappedFor(simulation));
simModelBatch.InitializeWith(modelCoreSimulation, _parameterIdentification.PathOfOptimizedParameterBelongingTo(simulation), simulationResultsName: Captions.ParameterIdentification.SimulationResultsForRun(RunResult.Index));
Expand Down Expand Up @@ -172,7 +172,10 @@ private void calculateJacobian()

private OptimizationRunResult performRun(IReadOnlyList<OptimizedParameterValue> values)
{
var optimizationRunResult = updateValuesAndCalculate(values);
//We clone the values here to ensure that we are not sharing the same parameter value instances as the PI algorithm
var clonedValues = values.Select(x => new OptimizedParameterValue(x.Name, x.Value, x.StartValue)).ToList();

var optimizationRunResult = updateValuesAndCalculate(clonedValues);

updateRunResult(optimizationRunResult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ public void should_update_the_status_of_the_run_result_to_completed()
public class When_the_parameter_identification_run_is_running_the_simulations : concern_for_ParameterIdentificationRun
{
private Func<IReadOnlyList<OptimizedParameterValue>, OptimizationRunResult> _objectiveFunction;
private OptimizedParameterValue _optimizedParameterValue;



protected override void Context()
{
Expand All @@ -268,12 +271,14 @@ protected override void Context()
.Invokes(x => { _objectiveFunction = x.GetArgument<Func<IReadOnlyList<OptimizedParameterValue>, OptimizationRunResult>>(1); })
.Returns(A.Fake<OptimizationRunProperties>());

_optimizedParameterValue = new OptimizedParameterValue("A", 100.0, 50d);

sut.Run(_cancellationToken);
}

protected override void Because()
{
_objectiveFunction(new[] {new OptimizedParameterValue("A", 100.0, 50d)});
_objectiveFunction(new[] { _optimizedParameterValue });
}

[Observation]
Expand All @@ -288,6 +293,15 @@ public void should_run_the_simulation()
{
A.CallTo(() => _simModelBatch.RunSimulation()).MustHaveHappened();
}

[Observation]
public void should_create_a_copy_of_the_optimized_parameter_values_and_save_them_into_the_current_result()
{
sut.BestResult.Values[0].Name.ShouldBeEqualTo(_optimizedParameterValue.Name);
sut.BestResult.Values[0].Value.ShouldBeEqualTo(_optimizedParameterValue.Value);
sut.BestResult.Values[0].StartValue.ShouldBeEqualTo(_optimizedParameterValue.StartValue);
sut.BestResult.Values[0].ShouldNotBeEqualTo(_optimizedParameterValue);
}
}

public class When_the_parameter_identification_run_is_running_multiple_simulations : concern_for_ParameterIdentificationRun
Expand Down
32 changes: 17 additions & 15 deletions tests/OSPSuite.Starter/Bootstrapping/ApplicationStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using System.Windows.Forms;
using Autofac;
using Castle.Facilities.TypedFactory;
using DevExpress.LookAndFeel;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
Expand All @@ -20,6 +21,7 @@
using OSPSuite.Helpers;
using OSPSuite.Infrastructure;
using OSPSuite.Infrastructure.Container.Autofac;
using OSPSuite.Infrastructure.Container.Castle;
using OSPSuite.Infrastructure.Export;
using OSPSuite.Infrastructure.Serialization;
using OSPSuite.Presentation;
Expand Down Expand Up @@ -72,11 +74,11 @@ private static SynchronizationContext getCurrentContext()

private static void initializeDependency()
{
var container = new AutofacContainer();
container.AddActivationHook<EventRegistrationHook>();
// var container = new CastleWindsorContainer();
// container.AddFacility<EventRegisterFacility>();
// container.AddFacility<TypedFactoryFacility>();
// var container = new AutofacContainer();
// container.AddActivationHook<EventRegistrationHook>();
var container = new CastleWindsorContainer();
container.AddFacility<EventRegisterFacility>();
container.AddFacility<TypedFactoryFacility>();


IoC.InitializeWith(container);
Expand Down Expand Up @@ -109,18 +111,18 @@ private static void initializeDependency()


container.Register<DxContainer, DxContainer>(LifeStyle.Singleton);
container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().ApplicationMenu).As<ApplicationMenu>();
container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().BarManager).As<BarManager>();
container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().PanelControl).As<PanelControl>();
container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().RibbonControl).As<RibbonControl>();
container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().RibbonBarManager).As<RibbonBarManager>();
container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().UserLookAndFeel).As<UserLookAndFeel>();
container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().XtraTabbedMdiManager).As<XtraTabbedMdiManager>();
// container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().ApplicationMenu).As<ApplicationMenu>();
// container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().BarManager).As<BarManager>();
// container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().PanelControl).As<PanelControl>();
// container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().RibbonControl).As<RibbonControl>();
// container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().RibbonBarManager).As<RibbonBarManager>();
// container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().UserLookAndFeel).As<UserLookAndFeel>();
// container.AutofacBuilder.Register(c => c.Resolve<DxContainer>().XtraTabbedMdiManager).As<XtraTabbedMdiManager>();

container.Register<RegionsContainer, RegionsContainer>(LifeStyle.Singleton);
container.AutofacBuilder.Register(c => c.Resolve<RegionsContainer>().Journal).Keyed<IRegion>(RegionNames.Journal.Name);
container.AutofacBuilder.Register(c => c.Resolve<RegionsContainer>().Comparison).Keyed<IRegion>(RegionNames.Comparison.Name);
container.AutofacBuilder.Register(c => c.Resolve<RegionsContainer>().Explorer).Keyed<IRegion>(RegionNames.Explorer.Name);
// container.AutofacBuilder.Register(c => c.Resolve<RegionsContainer>().Journal).Keyed<IRegion>(RegionNames.Journal.Name);
// container.AutofacBuilder.Register(c => c.Resolve<RegionsContainer>().Comparison).Keyed<IRegion>(RegionNames.Comparison.Name);
// container.AutofacBuilder.Register(c => c.Resolve<RegionsContainer>().Explorer).Keyed<IRegion>(RegionNames.Explorer.Name);
}


Expand Down
1 change: 1 addition & 0 deletions tests/OSPSuite.Starter/OSPSuite.Starter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<ProjectReference Include="..\..\src\OSPSuite.Assets\OSPSuite.Assets.csproj" />
<ProjectReference Include="..\..\src\OSPSuite.Core\OSPSuite.Core.csproj" />
<ProjectReference Include="..\..\src\OSPSuite.Infrastructure.Autofac\OSPSuite.Infrastructure.Autofac.csproj" />
<ProjectReference Include="..\..\src\OSPSuite.Infrastructure.Castle\OSPSuite.Infrastructure.Castle.csproj" />
<ProjectReference Include="..\..\src\OSPSuite.Infrastructure.Export\OSPSuite.Infrastructure.Export.csproj" />
<ProjectReference Include="..\..\src\OSPSuite.Infrastructure.Import\OSPSuite.Infrastructure.Import.csproj" />
<ProjectReference Include="..\..\src\OSPSuite.Infrastructure.Reporting\OSPSuite.Infrastructure.Reporting.csproj" />
Expand Down

0 comments on commit 3d13a12

Please sign in to comment.