|
|
|
|
@@ -1,12 +1,12 @@
|
|
|
|
|
using Enigmos.Boards;
|
|
|
|
|
using Enigmos.Modules.InterlayerModules;
|
|
|
|
|
using Enigmos.Modules.SubModules;
|
|
|
|
|
using Enigmos.Ports.DataPorts;
|
|
|
|
|
using Godot;
|
|
|
|
|
using Nocturnis.DataStructures;
|
|
|
|
|
using Nocturnis.DataStructures.ConfigurableParameters;
|
|
|
|
|
using Nocturnis.DataStructures.DataPortGroups;
|
|
|
|
|
using Nocturnis.Enigmos.Modules;
|
|
|
|
|
using Nocturnis.Enigmos.Modules.InterlayerModules;
|
|
|
|
|
using Nocturnis.Enigmos.Ports;
|
|
|
|
|
using Nocturnis.Enigmos.Ports.DataPorts;
|
|
|
|
|
using Nocturnis.Enigmos.Ports.DataPorts.Directions;
|
|
|
|
|
@@ -18,15 +18,14 @@ namespace Enigmos.Modules.ProgrammableModules.OptimizationModule;
|
|
|
|
|
public partial class OptimizationModule : ProgrammableModule,
|
|
|
|
|
IPolymorphismModule,
|
|
|
|
|
IParameterizedModule,
|
|
|
|
|
IOptimizationModule
|
|
|
|
|
IInternalComputationalModule,
|
|
|
|
|
IEnumerableProcessingModule
|
|
|
|
|
{
|
|
|
|
|
public bool OptimizationFinished { get; set; }
|
|
|
|
|
public bool OptimizationStarted { get; set; }
|
|
|
|
|
public bool ComputationFinished { get; set; }
|
|
|
|
|
public bool ComputationStarted { get; set; }
|
|
|
|
|
private double? CachedOptimizeValue { get; set; }
|
|
|
|
|
public IDataInPort? ArrayInput { get; set; }
|
|
|
|
|
public IInterlayerDataInModule[] ExplicitOutputs { get; set; } = Array.Empty<IInterlayerDataInModule>();
|
|
|
|
|
public IInterlayerDataOutModule[] ImplicitInputs { get; set; } = Array.Empty<IInterlayerDataOutModule>();
|
|
|
|
|
public IData[] CachedInput { get; set; } = Array.Empty<IData>();
|
|
|
|
|
public IData[] CachedInputArray { get; set; } = Array.Empty<IData>();
|
|
|
|
|
public int ProcessingIndex { get; set; }
|
|
|
|
|
private IBoolParameter? UsingMax { get; set; }
|
|
|
|
|
public IData CachedResult { get; set; } =
|
|
|
|
|
@@ -41,8 +40,8 @@ public partial class OptimizationModule : ProgrammableModule,
|
|
|
|
|
|
|
|
|
|
private InterlayerDataInModule[] ExplicitInputs { get; set; } = Array.Empty<InterlayerDataInModule>();
|
|
|
|
|
private OptimizationSelectorModule? Selector { get; set; }
|
|
|
|
|
private OptimizationOutputModule? Output { get; set; }
|
|
|
|
|
public override IEnumerable<IBasePort> Ports => new[] { ArrayInput! };
|
|
|
|
|
private OutputSubModule? Output { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public new OptimizationModuleBoard UnderlyingBoard
|
|
|
|
|
{
|
|
|
|
|
@@ -54,14 +53,9 @@ public partial class OptimizationModule : ProgrammableModule,
|
|
|
|
|
public HashSet<IDataPortGroup> ConfigurablePortGroups { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<IBasePort> ExplicitPorts =>
|
|
|
|
|
new IBasePort[] { ArrayInput!, Output!.Output! }
|
|
|
|
|
new IBasePort[] { ArrayInput!, Output!.Out! }
|
|
|
|
|
.Union<IBasePort>(ExplicitInputs.Select(c => c.DataIn)!);
|
|
|
|
|
|
|
|
|
|
public override BaseModule[] SubModules =>
|
|
|
|
|
ExplicitInputs
|
|
|
|
|
.Union(new BaseModule[] { Output! })
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<IBasePort> ImplicitPorts =>
|
|
|
|
|
new IBasePort[] { UnderlyingBoard.InputProvider!.Output!, UnderlyingBoard.Selector!.Selector! }
|
|
|
|
|
.Union(UnderlyingBoard.ImplicitDataOuts.Select(c => c.DataOut))!;
|
|
|
|
|
@@ -69,14 +63,14 @@ public partial class OptimizationModule : ProgrammableModule,
|
|
|
|
|
public override void Init()
|
|
|
|
|
{
|
|
|
|
|
base.Init();
|
|
|
|
|
UnderlyingBoard = GlobalProvider.SceneProvider!
|
|
|
|
|
.AssetMapper<OptimizationModuleBoard>()
|
|
|
|
|
UnderlyingBoard = GlobalProvider
|
|
|
|
|
.AssetMapper<OptimizationModuleBoard>.Scene
|
|
|
|
|
.Instantiate<OptimizationModuleBoard>();
|
|
|
|
|
UnderlyingBoard.Init();
|
|
|
|
|
InterlayerGroups = new IDataPortGroup[3];
|
|
|
|
|
ExplicitInputs = new InterlayerDataInModule[3];
|
|
|
|
|
InternalIterOut = this.GetPort<IDataInPort>("InternalIterOut");
|
|
|
|
|
Output = GetModule<OptimizationOutputModule>("Output");
|
|
|
|
|
Output = GetModule<OutputSubModule>("Output");
|
|
|
|
|
Output.Init();
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
|
{
|
|
|
|
|
@@ -85,8 +79,8 @@ public partial class OptimizationModule : ProgrammableModule,
|
|
|
|
|
UnderlyingBoard.ImplicitDataOuts[i].DualModule = ExplicitInputs[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OptimizationFinished = true;
|
|
|
|
|
CachedInput = Array.Empty<IData>();
|
|
|
|
|
ComputationFinished = true;
|
|
|
|
|
CachedInputArray = Array.Empty<IData>();
|
|
|
|
|
//CachedArray = Array.Empty<DataPackage>();
|
|
|
|
|
ProcessingIndex = 0;
|
|
|
|
|
CachedResult = GlobalProvider.DataStructureProvider!.NullData;
|
|
|
|
|
@@ -119,7 +113,7 @@ public partial class OptimizationModule : ProgrammableModule,
|
|
|
|
|
"Min",
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
Output.Output!.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
|
|
|
|
Output.Out!.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
|
|
|
|
Selector!.Selector!.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
|
|
|
|
ConfigurableParameters = new HashSet<IConfigurableParameter> { UsingMax };
|
|
|
|
|
ConfigurablePortGroups =
|
|
|
|
|
@@ -132,28 +126,28 @@ public partial class OptimizationModule : ProgrammableModule,
|
|
|
|
|
public void Inference()
|
|
|
|
|
{
|
|
|
|
|
StringName elementType = GlobalProvider.DataPackageTypeProvider!.ToElement(OptimizationGroup!.SelectedType);
|
|
|
|
|
Output!.Output!.SetDataType(elementType);
|
|
|
|
|
Output!.Out!.SetDataType(elementType);
|
|
|
|
|
UnderlyingBoard.InputProvider!.Output!.SetDataType(elementType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SoftReset() => UnderlyingBoard.Reset();
|
|
|
|
|
|
|
|
|
|
public void Optimize()
|
|
|
|
|
public void Compute()
|
|
|
|
|
{
|
|
|
|
|
if (OptimizationFinished)
|
|
|
|
|
if (ComputationFinished)
|
|
|
|
|
{
|
|
|
|
|
CachedOptimizeValue = null;
|
|
|
|
|
CachedInput = InternalArrayIn!.OutData.Get!.Array;
|
|
|
|
|
CachedInputArray = InternalArrayIn!.OutData.Get!.Array;
|
|
|
|
|
CachedResult = GlobalProvider.DataStructureProvider!.NewData(0, EnigmosConstant.DataPortTypes.Null);
|
|
|
|
|
ProcessingIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (ProcessingIndex < CachedInput.Length)
|
|
|
|
|
while (ProcessingIndex < CachedInputArray.Length)
|
|
|
|
|
{
|
|
|
|
|
SoftReset();
|
|
|
|
|
UnderlyingBoard.InputProvider!.Output!.OutData.UpdateCalculation(
|
|
|
|
|
cache =>
|
|
|
|
|
(CachedInput[ProcessingIndex].Data, CachedInput[ProcessingIndex].Type)!
|
|
|
|
|
(CachedInputArray[ProcessingIndex].Data, CachedInputArray[ProcessingIndex].Type)!
|
|
|
|
|
);
|
|
|
|
|
UnderlyingBoard.InputProvider.Output.OutData.Expire();
|
|
|
|
|
double currentValue = UnderlyingBoard.Selector!.Selector!.GetData.Get!.Double;
|
|
|
|
|
@@ -178,9 +172,7 @@ public partial class OptimizationModule : ProgrammableModule,
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Output!.Define();
|
|
|
|
|
OptimizationFinished = true;
|
|
|
|
|
ComputationFinished = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Calculated { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|