Skip to content

Commit 88a2bd7

Browse files
committed
Updated to .NET 9.0
Upgraded to Cpp 20 Changes facebook link to discord in help. Fixed bug which sometimes did not copy neuronengine.dll to output folder Added Gate synapse type Changed "reset" synpase weight from 0.0 to 0.2 so hebbian could work Fixed bug where RefractoryDelay was not properly saved/restored to network files Impreoved display of synapse animations Changed YesNo message boxes to OKCancel so ESC would work Several fixes to Synapse dragging
1 parent e395466 commit 88a2bd7

19 files changed

+579
-496
lines changed

BrainSimulator.sln

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ EndProject
88
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NeuronEngineWrapper", "NeuronEngineWrapper\NeuronEngineWrapper.vcxproj", "{8A980E58-4395-44F4-A506-DA2988F6AC0D}"
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrainSimulator", "BrainSimulator\BrainSimulator.csproj", "{C08F318A-B8E6-4187-9ED4-0A126B3B63A9}"
11+
ProjectSection(ProjectDependencies) = postProject
12+
{E7E63D8A-1C35-47C9-A19F-2BA549D230AF} = {E7E63D8A-1C35-47C9-A19F-2BA549D230AF}
13+
EndProjectSection
1114
EndProject
1215
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NeuronServer", "NeuronServer\NeuronServer.csproj", "{46D6A725-51A4-4849-B8AB-8C44B23B9D44}"
1316
EndProject
@@ -19,19 +22,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SetupFirewall", "SetupFirew
1922
EndProject
2023
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AutomatedTests", "AutomatedTests", "{23F38505-3BF9-44D4-B138-F7E57837D466}"
2124
ProjectSection(SolutionItems) = preProject
22-
AutomatedTests\_run_complete_test.cmd = AutomatedTests\_run_complete_test.cmd
23-
AutomatedTests\_run_set_1.cmd = AutomatedTests\_run_set_1.cmd
24-
AutomatedTests\_run_set_2.cmd = AutomatedTests\_run_set_2.cmd
25-
AutomatedTests\_run_set_3.cmd = AutomatedTests\_run_set_3.cmd
26-
AutomatedTests\_run_set_4.cmd = AutomatedTests\_run_set_4.cmd
27-
AutomatedTests\_run_wip_tests.cmd = AutomatedTests\_run_wip_tests.cmd
2825
AutomatedTests\keywords.resource = AutomatedTests\keywords.resource
2926
AutomatedTests\testset_1.robot = AutomatedTests\testset_1.robot
3027
AutomatedTests\testset_2.robot = AutomatedTests\testset_2.robot
3128
AutomatedTests\testset_3.robot = AutomatedTests\testset_3.robot
3229
AutomatedTests\testset_4.robot = AutomatedTests\testset_4.robot
3330
AutomatedTests\teststeps.py = AutomatedTests\teststeps.py
3431
AutomatedTests\testtoolkit.py = AutomatedTests\testtoolkit.py
32+
AutomatedTests\_run_complete_test.cmd = AutomatedTests\_run_complete_test.cmd
33+
AutomatedTests\_run_set_1.cmd = AutomatedTests\_run_set_1.cmd
34+
AutomatedTests\_run_set_2.cmd = AutomatedTests\_run_set_2.cmd
35+
AutomatedTests\_run_set_3.cmd = AutomatedTests\_run_set_3.cmd
36+
AutomatedTests\_run_set_4.cmd = AutomatedTests\_run_set_4.cmd
37+
AutomatedTests\_run_wip_tests.cmd = AutomatedTests\_run_wip_tests.cmd
3538
EndProjectSection
3639
EndProject
3740
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{1C458A63-D394-4406-9465-01FA35263D9E}"
@@ -46,7 +49,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{1C458A63
4649
EndProject
4750
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Installer", "Installer", "{A2928C3B-AE3F-4E47-9094-39ECEC5D3183}"
4851
ProjectSection(SolutionItems) = preProject
49-
Installer\_BRAINSIM2.nsi = Installer\_BRAINSIM2.nsi
5052
Installer\bsicon.ico = Installer\bsicon.ico
5153
Installer\build_installer.cmd = Installer\build_installer.cmd
5254
Installer\FileAssociation.nsh = Installer\FileAssociation.nsh
@@ -55,6 +57,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Installer", "Installer", "{
5557
Installer\SPLASH.bmp = Installer\SPLASH.bmp
5658
Installer\SPLASH.wav = Installer\SPLASH.wav
5759
Installer\unicon.ico = Installer\unicon.ico
60+
Installer\_BRAINSIM2.nsi = Installer\_BRAINSIM2.nsi
5861
EndProjectSection
5962
EndProject
6063
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GetVersionInfo", "GetVersionInfo\GetVersionInfo.csproj", "{853FC713-7A7F-4995-95E0-1396A82CA2B5}"

BrainSimulator/BrainSimulator.csproj

Lines changed: 417 additions & 405 deletions
Large diffs are not rendered by default.

BrainSimulator/MainWindow.xaml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,23 +206,23 @@
206206
<TextBlock FontSize="16" FontFamily="Segoe MDL2 Assets" Foreground="#FF00539C" >&#xE893;</TextBlock>
207207
</MenuItem.Icon>
208208
</MenuItem>
209-
<StackPanel Orientation="Horizontal" Width="72" >
209+
<StackPanel Orientation="Horizontal" Width="150" >
210210
<Label Content="Speed: " Padding="0,4,0,0"/>
211-
<TextBox Text="23" VerticalAlignment="Center" Width="16" x:Name="EngineSpeed" IsEnabled="False"/>
211+
<TextBox Text="23" VerticalAlignment="Center" Width="50" x:Name="EngineSpeed" IsEnabled="False"/>
212212
<StackPanel>
213-
<RepeatButton Content="^" Height="12" Interval="250" VerticalContentAlignment="Bottom" Padding="0,-1" Click="Button_EngineSpeedUpClick"/>
214-
<RepeatButton Content="˅" Height="12" Interval="250" VerticalContentAlignment="Top" Padding="-1,-3,0,0" Click="Button_EngineSpeedDnClick"/>
213+
<RepeatButton Content="^" Height="18" Interval="250" VerticalContentAlignment="Bottom" Padding="0,-1" Click="Button_EngineSpeedUpClick"/>
214+
<RepeatButton Content="˅" Height="18" Interval="250" VerticalContentAlignment="Top" Padding="-1,-3,0,0" Click="Button_EngineSpeedDnClick"/>
215215
</StackPanel>
216216
</StackPanel>
217-
<StackPanel Orientation="Horizontal" Width="100" x:Name="RefractoryGroup">
217+
<StackPanel Orientation="Horizontal" Width="150" x:Name="RefractoryGroup">
218218
<Label Content="Refractory: " Padding="0,4,0,0"/>
219-
<TextBox Text="0" VerticalAlignment="Center" Width="16" x:Name="Refractory" IsEnabled="False"/>
219+
<TextBox Text="0" VerticalAlignment="Center" Width="50" x:Name="Refractory" IsEnabled="False"/>
220220
<StackPanel>
221-
<RepeatButton Content="^" Height="12" Interval="250" VerticalContentAlignment="Bottom" Padding="0,-1" Click="Button_RefractoryUpClick"/>
222-
<RepeatButton Content="˅" Height="12" Interval="250" VerticalContentAlignment="Top" Padding="-1,-3,0,0" Click="Button_RefractoryDnClick"/>
221+
<RepeatButton Content="^" Height="18" Interval="250" VerticalContentAlignment="Bottom" Padding="0,-1" Click="Button_RefractoryUpClick"/>
222+
<RepeatButton Content="˅" Height="18" Interval="250" VerticalContentAlignment="Top" Padding="-1,-3,0,0" Click="Button_RefractoryDnClick"/>
223223
</StackPanel>
224224
</StackPanel>
225-
<StackPanel Orientation="Horizontal" Width="100" x:Name="ThreadCountGroup" >
225+
<StackPanel Orientation="Horizontal" Width="150" x:Name="ThreadCountGroup" >
226226
<Label Content="Threads: " Padding="0,4,0,0"/>
227227
<TextBox Text="-1" VerticalAlignment="Center" Width="37" x:Name="ThreadCount" TextChanged="ThreadCount_TextChanged"/>
228228
</StackPanel>
@@ -279,9 +279,9 @@
279279
<Image Source="/resources/github-9-24.ico"></Image>
280280
</MenuItem.Icon>
281281
</MenuItem>
282-
<MenuItem Header="Join Facebook discussion" Click="MenuItemOnlineDiscussions_Click" >
282+
<MenuItem Header="Join Discord discussion" Click="MenuItemOnlineDiscussions_Click" >
283283
<MenuItem.Icon>
284-
<Image Source="resources/facebook-3-24.ico"></Image>
284+
<Image Source="resources/discord_icon_24x24.ico"></Image>
285285
</MenuItem.Icon>
286286
</MenuItem>
287287
<MenuItem Header="Watch the YouTubeChannel" Click="MenuItemYouTube_Click" >
@@ -372,10 +372,11 @@
372372
<ComboBoxItem>Binary</ComboBoxItem>
373373
<ComboBoxItem>Hebbian1</ComboBoxItem>
374374
<ComboBoxItem>Hebbian2</ComboBoxItem>
375-
<!--<ComboBoxItem>Hebbian3</ComboBoxItem>-->
375+
<ComboBoxItem>Hebbian3</ComboBoxItem>
376+
<ComboBoxItem>Gate</ComboBoxItem>
376377
</ComboBox>
377378
<Label Width="10"></Label>
378-
<CheckBox x:Name="SynapseUpdate" VerticalAlignment="Center">Update from click</CheckBox>
379+
<CheckBox x:Name="SynapseUpdate" VerticalAlignment="Center" IsChecked="True">Update from click</CheckBox>
379380
<Label Width="30"></Label>
380381
</StackPanel>
381382
</DockPanel>

BrainSimulator/MainWindowEventHandlers.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using System.Windows;
1212
using System.Windows.Controls;
1313
using System.Windows.Input;
14+
using System.Windows.Media;
15+
using static BrainSimulator.NeuronArrayView;
1416

1517
namespace BrainSimulator
1618
{
@@ -69,7 +71,25 @@ private void Window_KeyDown(object sender, KeyEventArgs e)
6971
theNeuronArrayView.ClearSelection();
7072
Update();
7173
}
72-
//TODO here is where we'd add deleting the last-clicked module (issue #160) should we choose to implement it
74+
if (arrayView.theCanvas.Cursor == Cursors.Arrow)
75+
{
76+
//if the mouse is currently on a synapse, delete it
77+
Point position = Mouse.GetPosition(arrayView.theCanvas);
78+
HitTestResult result = VisualTreeHelper.HitTest(arrayView.theCanvas, position);
79+
if (result != null && result.VisualHit is FrameworkElement theShape)
80+
{
81+
if ((shapeType)theShape.GetValue(ShapeType) == shapeType.Synapse)
82+
{
83+
int source = (int)theShape.GetValue(SynapseView.SourceIDProperty);
84+
int target = (int)theShape.GetValue(SynapseView.TargetIDProperty);
85+
//float weight = (float)theShape.GetValue(SynapseView.WeightValProperty);
86+
Neuron sourceNeuron = MainWindow.theNeuronArray.GetCompleteNeuron(source);
87+
MainWindow.theNeuronArray.SetUndoPoint();
88+
sourceNeuron.DeleteSynapseWithUndo(target);
89+
arrayView.Update();
90+
}
91+
}
92+
}
7393
}
7494
if (e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl)
7595
{
@@ -747,7 +767,7 @@ private void OpenBrowserWindowAndRepositionIt(string thePage)
747767
}
748768
}
749769
}
750-
found: ;
770+
found:;
751771
try
752772
{
753773
if (helpProcessTab != null)

BrainSimulator/ModuleViewMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ private static void Mi_Click(object sender, RoutedEventArgs e)
474474
{
475475
//TODO: Add some UI for this:
476476
//s.model = Synapse.modelType.Hebbian2;
477-
n.AddSynapseWithUndo(s.targetNeuron, 0, s.model);
477+
n.AddSynapseWithUndo(s.targetNeuron, 0.2f, s.model);
478478
s.Weight = 0;
479479
}
480480
}

BrainSimulator/NeuronArray.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public void RemoveLabelFromCache(int nID)
6363
{
6464
labelCache.Remove(nID);
6565
}
66-
catch { };
66+
catch { }
67+
;
6768
}
6869
public string GetLabelFromCache(int nID)
6970
{
@@ -88,7 +89,10 @@ public List<int> GetKeysFromLabelCache()
8889
}
8990

9091
public int RefractoryDelay
91-
{ get => refractoryDelay; set { refractoryDelay = value; SetRefractoryDelay(refractoryDelay); } }
92+
{
93+
get => refractoryDelay;
94+
set { refractoryDelay = value; SetRefractoryDelay(refractoryDelay); }
95+
}
9296

9397
public void Initialize(int count, int inRows, bool clipBoard = false)
9498
{

BrainSimulator/NeuronArrayView.xaml.cs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -463,19 +463,6 @@ public void UpdateNeuronColors()
463463
}
464464
else
465465
{
466-
//for small arrays, repaint everything so synapse weights will update
467-
//if (false) //use this for testing of
468-
//if (neuronsOnScreen.Count < 451 && scale == 1)
469-
//{
470-
// Update();
471-
// if (MainWindow.theNeuronArray != null)
472-
// {
473-
// MainWindow.UpdateDisplayLabel(dp.NeuronDisplaySize);
474-
// MainWindow.UpdateEngineLabel((int)MainWindow.theNeuronArray.lastFireCount);
475-
// }
476-
// return;
477-
//}
478-
479466
SetTargetNeuronSymbol();
480467
if (animationCanvas == null)
481468
{
@@ -502,33 +489,43 @@ public void UpdateNeuronColors()
502489
if (MainWindow.theNeuronArray.animateSynapses)
503490
{
504491
//synapse animation trial
505-
float electronSize = dp.NeuronDisplaySize * .2f;
506492
n.synapses = MainWindow.theNeuronArray.GetSynapsesList(n.id);
507493
Point pStart = dp.pointFromNeuron(n.id);
508494
//pstart is the UL corner of the neuron...adjust to the center
509495
pStart.X += dp.NeuronDisplaySize / 2;
510496
pStart.Y += dp.NeuronDisplaySize / 2;
511497
foreach (Synapse synapse in n.synapses)
512498
{
499+
float electronSize = 3+ dp.NeuronDisplaySize * .3f * Math.Abs(synapse.weight);
513500
Point pTarget = dp.pointFromNeuron(synapse.targetNeuron);
514501
//pTarget is the UL corner of the neuron...adjust to the center
515502
pTarget.X += dp.NeuronDisplaySize / 2;
516503
pTarget.Y += dp.NeuronDisplaySize / 2;
517504

518505
//put the little bar graph in the center of hebbian3 synapses
519-
if ((synapse.model == Synapse.modelType.Hebbian3 || synapse.model == Synapse.modelType.Hebbian2)
506+
if ((synapse.model == Synapse.modelType.Hebbian3 ||
507+
synapse.model == Synapse.modelType.Hebbian2 ||
508+
synapse.model == Synapse.modelType.Hebbian1)
520509
&& dp.NeuronDisplaySize > 75)
521510
{
522-
var graph = SynapseView.GetWeightBargraph(pStart, pTarget, synapse.weight);
511+
var graph = SynapseView.GetWeightBargraph(pStart, pTarget,
512+
n.id,synapse.targetNeuron, synapse.weight,synapse.model);
523513
synapseGraphCanvas.Children.Add(graph);
524514
}
525-
if (n.lastCharge < 1) continue;
515+
if (n.lastCharge < 1 && synapse.model != Synapse.modelType.Gate) continue;
516+
long lastFired = MainWindow.theNeuronArray.GetCompleteNeuron(n.id).LastFired;
517+
if (synapse.model == Synapse.modelType.Gate &&
518+
lastFired < MainWindow.theNeuronArray.Generation - 3) continue;
526519

527520
//animate charges along the axons
528521
var fill = Brushes.Yellow;
529522
if (synapse.weight < 0)
530523
fill = Brushes.DeepPink;
531-
524+
if (synapse.model == Synapse.modelType.Gate)
525+
{
526+
fill = Brushes.Blue;
527+
electronSize = dp.NeuronDisplaySize * .15f;
528+
}
532529
// Create the disk (Ellipse)
533530
Ellipse disk = new Ellipse
534531
{

BrainSimulator/NeuronArrayViewClipBoard.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@ public void MoveNeurons(bool dragging = false)
416416

417417
if (!IsDestinationClear(neuronsToMove, offset))
418418
{
419-
MessageBoxResult result = MessageBox.Show("Some destination neurons are in use and will be overwritten, continue?\n\nYou can also right-click the final destination neuron and select 'Move Here.'", "Continue", MessageBoxButton.YesNo);
420-
if (result == MessageBoxResult.No) return;
419+
MessageBoxResult result = MessageBox.Show("Some destination neurons are in use and will be overwritten, continue?\n\nYou can also right-click the final destination neuron and select 'Move Here.'", "Continue", MessageBoxButton.OKCancel);
420+
if (result != MessageBoxResult.OK) return;
421421
}
422422

423423
if (!dragging)

BrainSimulator/NeuronArrayViewMouse.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55

66

77
using System;
8-
using System.Collections.Generic;
98
using System.Diagnostics;
10-
using System.Linq;
11-
using System.Text;
12-
using System.Threading.Tasks;
139
using System.Windows;
1410
using System.Windows.Controls;
1511
using System.Windows.Input;
1612
using System.Windows.Media;
1713
using System.Windows.Shapes;
18-
using System.Windows.Threading;
1914

2015
namespace BrainSimulator
2116
{
@@ -136,6 +131,8 @@ private shapeType SetMouseCursorShape(MouseEventArgs e, out FrameworkElement the
136131
break;
137132
case shapeType.Synapse:
138133
theCanvas.Cursor = Cursors.Arrow;
134+
if (theShape is not Path && theShape is not Ellipse) //synapse hits might be in the bar graph
135+
theShape = (Canvas)theShape.Parent;
139136
break;
140137
case shapeType.Neuron:
141138
theCanvas.Cursor = Cursors.UpArrow;

BrainSimulator/NeuronArrayViewMouseActions.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
using System;
88
using System.Collections.Generic;
99
using System.Diagnostics;
10-
using System.Linq;
11-
using System.Text;
12-
using System.Threading.Tasks;
1310
using System.Windows;
1411
using System.Windows.Controls;
1512
using System.Windows.Input;
@@ -139,7 +136,7 @@ private static void OpenSynapseContextMenu(FrameworkElement theShape)
139136
{
140137
int source = (int)theShape.GetValue(SynapseView.SourceIDProperty);
141138
int target = (int)theShape.GetValue(SynapseView.TargetIDProperty);
142-
float weight = (float)theShape.GetValue(SynapseView.WeightValProperty);
139+
//float weight = (float)theShape.GetValue(SynapseView.WeightValProperty);
143140
Neuron n1 = MainWindow.theNeuronArray.GetCompleteNeuron(source);
144141
n1 = MainWindow.theNeuronArray.AddSynapses(n1);
145142
if (n1.FindSynapse(target) is Synapse s1)
@@ -161,6 +158,17 @@ private void StartSynapseDragging(FrameworkElement theShape)
161158
currentOperation = CurrentOperation.draggingSynapse;
162159
Canvas parentCanvas = (Canvas)theShape.Parent;
163160
parentCanvas.Children.Remove(theShape);
161+
162+
//to fix bug where clicking on a synapse accidently removes it
163+
Shape l = SynapseView.GetSynapseShape
164+
(dp.pointFromNeuron(mouseDownNeuronIndex),
165+
dp.pointFromNeuron(mouseDownNeuronIndex),
166+
LastSynapseModel
167+
);
168+
l.Stroke = new SolidColorBrush(Utils.RainbowColorFromValue(LastSynapseWeight));
169+
if (!(l is Ellipse))
170+
l.Fill = l.Stroke;
171+
synapseShape = l;
164172
}
165173

166174
private void DragSynapse(int currentNeuron)
@@ -189,7 +197,7 @@ private void FinishDraggingSynapse(MouseButtonEventArgs e)
189197
LimitMousePostion(ref p1);
190198
int index = dp.NeuronFromPoint(p1);
191199
MainWindow.theNeuronArray.SetUndoPoint();
192-
MainWindow.arrayView.AddShowSynapses(mouseDownNeuronIndex);
200+
//MainWindow.arrayView.AddShowSynapses(mouseDownNeuronIndex);
193201
MainWindow.theNeuronArray.GetNeuron(mouseDownNeuronIndex).
194202
AddSynapseWithUndo(index, LastSynapseWeight, LastSynapseModel);
195203
}
@@ -450,8 +458,8 @@ private void MoveModule(FrameworkElement theShape, int currentNeuron)
450458
}
451459
if (!IsDestinationClear(neuronsToMove, delta))
452460
{
453-
MessageBoxResult result1 = MessageBox.Show("Some destination neurons are in use and will be overwritten, continue?", "Continue", MessageBoxButton.YesNo);
454-
if (result1 != MessageBoxResult.Yes)
461+
MessageBoxResult result1 = MessageBox.Show("Some destination neurons are in use and will be overwritten, continue?", "Continue", MessageBoxButton.OKCancel);
462+
if (result1 != MessageBoxResult.OK)
455463
{
456464
return;
457465
}

0 commit comments

Comments
 (0)