Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Dyqui.ConsoleDemo/Dyqui.ConsoleDemo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Reactive" Version="4.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Dyquo.PSO\Dyquo.PSO.csproj" />
</ItemGroup>

</Project>
85 changes: 85 additions & 0 deletions Dyqui.ConsoleDemo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

namespace Dyqui.ConsoleDemo
{
using System;
using System.Linq;
using System.Reactive.Linq;

using Dyqui.PSO;

class Program
{
static void Main(string[] args)
{
RunSolver();
Console.ReadLine();
}

private static async void RunSolver()
{
var solver = new Solver(ErrorFunction, GetPsoSolverOptions());
var data = solver.Initialize();

GetParticleUpdates(solver)
.Subscribe(particles =>
{
var result = particles.Where(p => p.Error != 0).Select(p => (xy: p.BestPosition, score: 1 / p.Error)).ToArray();
var x = result.WeightedAverage(a => a.xy[0], a => a.score);
var y = result.WeightedAverage(a => a.xy[1], a => a.score);
Console.WriteLine($"{x},{y}");
});

_ = await solver.SolveAsync(data);
}


static IObservable<Particle[]> GetParticleUpdates(Solver solver)
{
return Observable.FromEvent<EpochDelegate, SolverData>(
onNextHandler => (s, d) => onNextHandler(d),
d => solver.AfterEpoch += d,
d => solver.AfterEpoch -= d)
.Select(d =>d.Particles);


}


static double ErrorFunction(double[] pos)
{
double target = -0.42888194;
//double target = -100000; // To minimize without specific target

double f = Function2d(pos);

// Quadratic error
return (f - target) * (f - target);
}

static double Function2d(double x, double y)
{
return x * Math.Exp(-((x * x) + (y * y)));
}

static double Function2d(double[] pos)
{
var x = pos[0];
var y = pos[1];
return Function2d(x, y);
}

private static SolverOptions GetPsoSolverOptions() => new SolverOptions
{
NumDimensions = 2,
NumParticles = 50,
MaxEpochs = 500,
MinimumX = -10.0,
MaximumX = 10.0,
AcceptanceError = 0.00000000,
InertiaWeight = 0.729,
C1CognitiveWeight = 1.5,
C2SocialWeight = 1.5,
ParticleResetProbability = 0.001,
};
}
}
10 changes: 4 additions & 6 deletions Dyquo.Charts3d/Dyquo.Charts3d.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="HelixToolkit, Version=2015.1.715.0, Culture=neutral, PublicKeyToken=52aa3500039caf0d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\helix-toolkit\Source\HelixToolkit.Wpf\bin\Debug\HelixToolkit.dll</HintPath>
<Reference Include="HelixToolkit, Version=2.10.0.0, Culture=neutral, PublicKeyToken=52aa3500039caf0d, processorArchitecture=MSIL">
<HintPath>..\packages\HelixToolkit.2.10.0\lib\netstandard1.1\HelixToolkit.dll</HintPath>
</Reference>
<Reference Include="HelixToolkit.Wpf, Version=2015.1.715.0, Culture=neutral, PublicKeyToken=52aa3500039caf0d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\helix-toolkit\Source\HelixToolkit.Wpf\bin\Debug\HelixToolkit.Wpf.dll</HintPath>
<Reference Include="HelixToolkit.Wpf, Version=2.10.0.0, Culture=neutral, PublicKeyToken=52aa3500039caf0d, processorArchitecture=MSIL">
<HintPath>..\packages\HelixToolkit.Wpf.2.10.0\lib\net45\HelixToolkit.Wpf.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
Expand Down
4 changes: 2 additions & 2 deletions Dyquo.Charts3d/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<!--<package id="HelixToolkit" version="2015.1.715" targetFramework="net461" />
<package id="HelixToolkit.Wpf" version="2015.1.715" targetFramework="net461" />-->
<package id="HelixToolkit" version="2.10.0" targetFramework="net461" />
<package id="HelixToolkit.Wpf" version="2.10.0" targetFramework="net461" />
</packages>
14 changes: 13 additions & 1 deletion Dyquo.Optimization.UI/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.Serialization.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
62 changes: 53 additions & 9 deletions Dyquo.Optimization.UI/Dyquo.Optimization.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -35,17 +37,24 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Eto, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Eto.Forms.2.2.0\lib\net45\Eto.dll</HintPath>
<Private>True</Private>
<Reference Include="Eto, Version=2.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Eto.Forms.2.4.1\lib\netstandard1.0\Eto.dll</HintPath>
</Reference>
<Reference Include="Eto.OxyPlot.Wpf, Version=1.0.5911.42160, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Eto.OxyPlot.Wpf.1.2.0-beta\lib\net45\Eto.OxyPlot.Wpf.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Eto.Wpf, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Eto.Platform.Wpf.2.2.0\lib\net45\Eto.Wpf.dll</HintPath>
<Private>True</Private>
<Reference Include="Eto.Wpf, Version=2.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Eto.Platform.Wpf.2.4.1\lib\net45\Eto.Wpf.dll</HintPath>
</Reference>
<Reference Include="HelixToolkit, Version=2.10.0.0, Culture=neutral, PublicKeyToken=52aa3500039caf0d, processorArchitecture=MSIL">
<HintPath>..\packages\HelixToolkit.2.10.0\lib\netstandard1.1\HelixToolkit.dll</HintPath>
</Reference>
<Reference Include="HelixToolkit.Wpf, Version=2.10.0.0, Culture=neutral, PublicKeyToken=52aa3500039caf0d, processorArchitecture=MSIL">
<HintPath>..\packages\HelixToolkit.Wpf.2.10.0\lib\net45\HelixToolkit.Wpf.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Xaml.Behaviors, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.3\lib\net45\Microsoft.Xaml.Behaviors.dll</HintPath>
</Reference>
<Reference Include="OxyPlot, Version=1.0.0.0, Culture=neutral, PublicKeyToken=638079a8f0bd61e9, processorArchitecture=MSIL">
<HintPath>..\packages\OxyPlot.Core.1.0.0\lib\net45\OxyPlot.dll</HintPath>
Expand All @@ -55,8 +64,36 @@
<HintPath>..\packages\OxyPlot.Wpf.1.0.0\lib\net45\OxyPlot.Wpf.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="ReactiveProperty, Version=6.1.3.0, Culture=neutral, PublicKeyToken=910d1732782c71cb, processorArchitecture=MSIL">
<HintPath>..\packages\ReactiveProperty.6.1.4\lib\net461\ReactiveProperty.dll</HintPath>
</Reference>
<Reference Include="ReactiveProperty.NET46, Version=6.1.3.0, Culture=neutral, PublicKeyToken=3d1fed915120cbde, processorArchitecture=MSIL">
<HintPath>..\packages\ReactiveProperty.6.1.4\lib\net461\ReactiveProperty.NET46.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Annotations, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.ComponentModel.Annotations.4.6.0\lib\net461\System.ComponentModel.Annotations.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Data" />
<Reference Include="System.Reactive, Version=4.2.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reactive.4.2.0\lib\net46\System.Reactive.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Runtime.Serialization.Primitives, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.Serialization.Primitives.4.3.0\lib\net46\System.Runtime.Serialization.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -122,12 +159,19 @@
<Project>{BBF1973F-289C-418B-B5E1-2251F77A4BB1}</Project>
<Name>Dyquo.Charts3d</Name>
</ProjectReference>
<ProjectReference Include="..\dyquo.optimization.swarm\Dyquo.Optimization.Swarm.csproj">
<Project>{01632468-842a-42eb-8cdb-31cc24e50e44}</Project>
<Name>Dyquo.Optimization.Swarm</Name>
<ProjectReference Include="..\Dyquo.PSO\Dyquo.PSO.csproj">
<Project>{1d7aa1ac-b358-4906-a36f-9007831cb7c8}</Project>
<Name>Dyquo.PSO</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Eto.Forms.2.4.1\build\Eto.Forms.targets" Condition="Exists('..\packages\Eto.Forms.2.4.1\build\Eto.Forms.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Eto.Forms.2.4.1\build\Eto.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Eto.Forms.2.4.1\build\Eto.Forms.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
14 changes: 10 additions & 4 deletions Dyquo.Optimization.UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Dyquo.Optimization.UI"
xmlns:Charts3d="clr-namespace:Dyquo.Charts3d;assembly=Dyquo.Charts3d"
xmlns:charts3d="clr-namespace:Dyquo.Charts3d;assembly=Dyquo.Charts3d"
x:Class="Dyquo.Optimization.UI.MainWindow"
mc:Ignorable="d"
Title="Optimizer" Height="720" Width="1024">
<Grid>

<Charts3d:Chart3d x:Name="Show3d"/>
<charts3d:Chart3d x:Name="Show3d"/>

<Grid Height="98" VerticalAlignment="Top" Margin="0,0,0,0">
<Button x:Name="RunButton" Content="Run" Margin="9,12,0,0" VerticalAlignment="Top" Click="button_Click" Height="68" HorizontalAlignment="Left" Width="73" FontSize="26" Background="{x:Null}" BorderBrush="#FFC7AFAF"/>
<Button x:Name="RunButton" Content="Run" Margin="9,12,0,0" VerticalAlignment="Top"
Command="{Binding RunCommand}"
Height="68" HorizontalAlignment="Left" Width="73" FontSize="26" Background="{x:Null}" BorderBrush="#FFC7AFAF"/>

<Label x:Name="StatusLabel" Content="Solver idle." HorizontalAlignment="Left" Margin="92,-1,0,0" VerticalAlignment="Top" Width="426" FontSize="26"/>
<Label x:Name="StatusLabel" Content="{Binding Status.Value}" HorizontalAlignment="Left" Margin="92,-1,0,0" VerticalAlignment="Top" Width="426" FontSize="26">
<Label.ContentStringFormat>
Solver {0}
</Label.ContentStringFormat>
</Label>
<Label Content="Goal is to find absolute minimum of the function." HorizontalAlignment="Left" Margin="94,36,0,0" VerticalAlignment="Top" Width="337"/>
<Label x:Name="CycleInfoLabel" Content="" HorizontalAlignment="Left" Margin="94,56,0,0" VerticalAlignment="Top" Width="337"/>

Expand Down
Loading