Пример #1
0
        public PropertiesDlg()
        {
            InitializeComponent();
            if (MainWindow.theNeuronArray == null)
            {
                Close(); return;
            }

            txtFileName.Text    = MainWindow.currentFileName;
            txtFileName.ToolTip = MainWindow.currentFileName;
            txtRows.Text        = MainWindow.theNeuronArray.rows.ToString("N0");
            txtColumns.Text     = (MainWindow.theNeuronArray.arraySize / MainWindow.theNeuronArray.rows).ToString("N0");
            txtNeurons.Text     = MainWindow.theNeuronArray.arraySize.ToString("N0");
            if (MainWindow.useServers)
            {
                NeuronClient.GetServerList();
                Thread.Sleep(1000);
                txtNeuronsInUse.Text = NeuronClient.serverList.Sum(x => x.neuronsInUse).ToString("N0");
                txtSynapses.Text     = NeuronClient.serverList.Sum(x => x.totalSynapses).ToString("N0");
            }
            else
            {
                MainWindow.theNeuronArray.GetCounts(out long synapseCount, out int neuronInUseCount);
                txtNeuronsInUse.Text = neuronInUseCount.ToString("N0");
                txtSynapses.Text     = synapseCount.ToString("N0");
            }
        }
Пример #2
0
 private void UpdateServerTextBox()
 {
     if (cbUseServers.IsChecked == true)
     {
         NeuronClient.GetServerList();
         Thread.Sleep(1000);
         if (NeuronClient.serverList.Count == 0)
         {
             ServerList.Text           = "No Servers Detected";
             buttonSpeedTest.IsEnabled = false;
         }
         else
         {
             int.TryParse(textBoxColumns.Text, out cols);
             int.TryParse(textBoxRows.Text, out rows);
             ServerList.Text       = "";
             MainWindow.useServers = true;
             int numServers    = NeuronClient.serverList.Count;
             int neuronsNeeded = rows * cols;
             for (int i = 0; i < numServers; i++)
             {
                 NeuronClient.Server s = NeuronClient.serverList[i];
                 s.firstNeuron    = i * neuronsNeeded / numServers;
                 s.lastNeuron     = (i + 1) * neuronsNeeded / numServers;
                 ServerList.Text += s.ipAddress.ToString() + " " + s.name + " " + s.firstNeuron + " " + s.lastNeuron + "\n";
             }
             buttonSpeedTest.IsEnabled = true;
         }
     }
     else
     {
         ServerList.Text = "";
     }
 }
Пример #3
0
        public Neuron GetCompleteNeuron(int i)
        {
            if (MainWindow.useServers)
            {
                Neuron retVal = NeuronClient.GetNeuron(i);
                //retVal.synapses = NeuronClient.GetSynapses(i);
                //retVal.synapsesFrom = NeuronClient.GetSynapsesFrom(i);
                return(retVal);
            }
            else
            {
                NeuronPartial n = GetPartialNeuron(i);

                Neuron retVal = new Neuron();

                retVal.id            = n.id;
                retVal.currentCharge = n.currentCharge;
                retVal.lastCharge    = n.lastCharge;
                retVal.lastFired     = n.lastFired;
                retVal.inUse         = n.inUse;
                retVal.leakRate      = n.leakRate;
                retVal.model         = n.model;
                retVal.axonDelay     = n.axonDelay;

                retVal.label        = GetNeuronLabel(i);
                retVal.synapses     = GetSynapsesList(i);
                retVal.synapsesFrom = GetSynapsesFromList(i);
                return(retVal);
            }
        }
Пример #4
0
        public Neuron GetCompleteNeuron(int i, bool fromClipboard = false)
        {
            if (MainWindow.useServers && !fromClipboard)
            {
                Neuron retVal = NeuronClient.GetNeuron(i);
                //retVal.synapses = NeuronClient.GetSynapses(i);
                //retVal.synapsesFrom = NeuronClient.GetSynapsesFrom(i);
                return(retVal);
            }
            else
            {
                NeuronPartial n = GetPartialNeuron(i);

                Neuron retVal = new Neuron();

                retVal.id            = n.id;
                retVal.currentCharge = n.currentCharge;
                retVal.lastCharge    = n.lastCharge;
                retVal.lastFired     = n.lastFired;
                retVal.inUse         = n.inUse;
                retVal.leakRate      = n.leakRate;
                retVal.model         = n.model;
                retVal.axonDelay     = n.axonDelay;

                retVal.label = retVal.Label;// GetNeuronLabel(i);
                if (retVal.ToolTip != "")
                {
                    retVal.label += Neuron.toolTipSeparator + retVal.ToolTip;
                }

                retVal.synapses     = GetSynapsesList(i);
                retVal.synapsesFrom = GetSynapsesFromList(i);
                return(retVal);
            }
        }
Пример #5
0
 private void CheckBoxUseServers_Checked(object sender, RoutedEventArgs e)
 {
     MainWindow.useServers     = true;
     buttonSpeedTest.IsEnabled = MainWindow.useServers;
     buttonRefresh.IsEnabled   = MainWindow.useServers;
     NeuronClient.Init();
     UpdateServerTextBox();
 }
Пример #6
0
 public Neuron AddSynapses(Neuron n)
 {
     if (MainWindow.useServers && n.Owner == MainWindow.theNeuronArray)
     {
         n.synapses     = NeuronClient.GetSynapses(n.id);
         n.synapsesFrom = NeuronClient.GetSynapsesFrom(n.id);
     }
     return(n);
 }
Пример #7
0
 public Neuron AddSynapses(Neuron n)
 {
     if (MainWindow.useServers)
     {
         n.synapses     = NeuronClient.GetSynapses(n.id);
         n.synapsesFrom = NeuronClient.GetSynapsesFrom(n.id);
     }
     return(n);
 }
Пример #8
0
 private void CheckBoxUseServers_Checked(object sender, RoutedEventArgs e)
 {
     NeuronClient.Init();
     UpdateServerTextBox();
     if (NeuronClient.serverList.Count > 0)
     {
         MainWindow.useServers = true;
     }
     buttonRefresh.IsEnabled = true;;
 }
Пример #9
0
        //PING speed test
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string s = ServerList.SelectedText;

            if (!IPAddress.TryParse(s, out IPAddress targetIp))
            {
                MessageBox.Show("Highlight an IP address");
                return;
            }
            NeuronClient.pingCount = 0;
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            string payload = NeuronClient.CreatePayload(1450);

            for (int i = 0; i < 100000; i++)
            {
                NeuronClient.SendToServer(targetIp, "Ping");
            }
            sw.Stop();
            double packetSendNoPayload = ((double)sw.ElapsedMilliseconds) / 100000.0;

            Thread.Sleep(1000);

            sw.Start();
            for (int i = 0; i < 100000; i++)
            {
                NeuronClient.SendToServer(targetIp, "Ping " + payload);
            }
            sw.Stop();
            double packetSendBigPayload = ((double)sw.ElapsedMilliseconds) / 100000.0;

            Thread.Sleep(1000);

            List <long> rawData = new List <long>();

            for (int i = 0; i < 1000; i++)
            {
                rawData.Add(NeuronClient.Ping(targetIp, ""));
            }
            double latencyNoPayload = ((double)rawData.Average()) / 10000.0;

            rawData.Clear();
            for (int i = 0; i < 1000; i++)
            {
                rawData.Add(NeuronClient.Ping(targetIp, payload));
            }
            double latencyBigPayload = ((double)rawData.Average()) / 10000.0;

            PingLabel.Content = "Packet Spd: " + packetSendNoPayload.ToString("F4") + "ms-" + packetSendBigPayload.ToString("F4") + "ms  R/T Latency:  "
                                + latencyNoPayload.ToString("F4") + "ms-" + latencyBigPayload.ToString("F4") + "ms " + NeuronClient.pingCount;
            PingLabel1.Visibility = Visibility.Visible;
        }
Пример #10
0
 public void SetCompleteNeuron(Neuron n)
 {
     if (MainWindow.useServers)
     {
         NeuronClient.SetNeuron(n);
     }
     else
     {
         int i = n.id;
         SetNeuronCurrentCharge(i, n.currentCharge);
         SetNeuronLastCharge(i, n.lastCharge);
         SetNeuronLabel(i, n.label);
         SetNeuronLeakRate(i, n.leakRate);
         SetNeuronModel(i, (int)n.model);
     }
 }
Пример #11
0
 public Neuron GetNeuronForDrawing(int i)
 {
     if (MainWindow.useServers)
     {
         Neuron retVal = NeuronClient.GetNeuron(i);
         return retVal;
     }
     else
     {
         Neuron retVal = new Neuron();
         retVal.LastCharge = GetNeuronLastCharge(i);
         retVal.inUse = GetNeuronInUse(i);
         retVal.label = GetNeuronLabel(i);
         return retVal;
     }
 }
Пример #12
0
 public void SetCompleteNeuron(Neuron n)
 {
     if (MainWindow.useServers && n.Owner == MainWindow.theNeuronArray)
     {
         NeuronClient.SetNeuron(n);
     }
     else
     {
         int i = n.id;
         SetNeuronCurrentCharge(i, n.currentCharge);
         SetNeuronLastCharge(i, n.lastCharge);
         SetNeuronLabel(i, n.label);
         SetNeuronLeakRate(i, n.leakRate);
         SetNeuronModel(i, (int)n.model);
         SetNeuronAxonDelay(i, n.axonDelay);
     }
 }
Пример #13
0
 public Neuron GetNeuronForDrawing(int i)
 {
     if (MainWindow.useServers)
     {
         Neuron retVal = NeuronClient.GetNeuron(i);
         return(retVal);
     }
     else
     {
         Neuron retVal = new Neuron();
         retVal.id         = i;
         retVal.LastCharge = GetNeuronLastCharge(i);
         retVal.inUse      = GetNeuronInUse(i);
         retVal.label      = GetNeuronLabel(i);
         retVal.model      = (Neuron.modelType)GetNeuronModel(i);
         retVal.leakRate   = GetNeuronLeakRate(i);
         retVal.axonDelay  = GetNeuronAxonDelay(i);
         return(retVal);
     }
 }
        public void MoveOneNeuron(Neuron n, Neuron nNewLocation, bool addUndo = true)
        {
            if (addUndo)
            {
                n.AddUndoInfo();
                nNewLocation.AddUndoInfo();
            }
            if (MainWindow.useServers)
            {
                n.synapses     = NeuronClient.GetSynapses(n.id);
                n.synapsesFrom = NeuronClient.GetSynapsesFrom(n.id);
            }

            //copy the neuron attributes and delete them from the old neuron.
            n.Copy(nNewLocation);
            MainWindow.theNeuronArray.SetCompleteNeuron(nNewLocation);
            if (FiringHistory.NeuronIsInFiringHistory(n.id))
            {
                FiringHistory.RemoveNeuronFromHistoryWindow(n.id);
                FiringHistory.AddNeuronToHistoryWindow(nNewLocation.id);
            }

            //for all the synapses going out this neuron, change to going from new location
            //don't use a foreach here because the body of the loop may delete a list entry
            for (int k = 0; k < n.Synapses.Count; k++)
            {
                Synapse s = n.Synapses[k];
                if (addUndo)
                {
                    if (s.targetNeuron != n.id)
                    {
                        nNewLocation.AddSynapseWithUndo(s.targetNeuron, s.weight, s.model);
                    }
                    else
                    {
                        nNewLocation.AddSynapseWithUndo(nNewLocation.id, s.weight, s.model);
                    }
                    n.DeleteSynapseWithUndo(n.synapses[k].targetNeuron);
                }
                else
                {
                    if (s.targetNeuron != n.id)
                    {
                        nNewLocation.AddSynapse(s.targetNeuron, s.weight, s.model);
                    }
                    else
                    {
                        nNewLocation.AddSynapse(nNewLocation.id, s.weight, s.model);
                    }
                    n.DeleteSynapse(n.synapses[k].targetNeuron);
                }
            }

            //for all the synapses coming into this neuron, change the synapse target to new location
            for (int k = 0; k < n.SynapsesFrom.Count; k++)
            {
                Synapse reverseSynapse = n.SynapsesFrom[k]; //(from synapses are sort-of backward
                if (reverseSynapse.targetNeuron != -1)      //?
                {
                    Neuron sourceNeuron = MainWindow.theNeuronArray.GetNeuron(reverseSynapse.targetNeuron);
                    sourceNeuron.DeleteSynapseWithUndo(n.id);
                    if (sourceNeuron.id != n.id)
                    {
                        if (addUndo)
                        {
                            sourceNeuron.AddSynapseWithUndo(nNewLocation.id, reverseSynapse.weight, reverseSynapse.model);
                        }
                        else
                        {
                            sourceNeuron.AddSynapse(nNewLocation.id, reverseSynapse.weight, reverseSynapse.model);
                        }
                    }
                }
            }

            n.Clear();
        }
        //copy the selection to a clipboard
        public void CopyNeurons()
        {
            //get list of neurons to copy
            List <int> neuronsToCopy = theSelection.EnumSelectedNeurons();

            theSelection.GetSelectedBoundingRectangle(out int X1o, out int Y1o, out int X2o, out int Y2o);
            MainWindow.myClipBoard = new NeuronArray();
            NeuronArray myClipBoard;

            myClipBoard = MainWindow.myClipBoard;
            myClipBoard.Initialize((X2o - X1o + 1) * (Y2o - Y1o + 1), (Y2o - Y1o + 1), true);
            boundarySynapsesOut.Clear();
            boundarySynapsesIn.Clear();

            //copy the neurons
            foreach (int nID in neuronsToCopy)
            {
                int destId = GetClipboardId(X1o, Y1o, nID);
                //copy the source neuron to the clipboard
                Neuron sourceNeuron = MainWindow.theNeuronArray.GetNeuron(nID);
                Neuron destNeuron   = sourceNeuron.Clone();
                destNeuron.Owner = myClipBoard;
                destNeuron.Id    = destId;
                destNeuron.Label = sourceNeuron.Label;
                myClipBoard.SetNeuron(destId, destNeuron);
            }

            //copy the synapses (this is two-pass so we make sure all neurons exist prior to copying
            foreach (int nID in neuronsToCopy)
            {
                Neuron sourceNeuron = MainWindow.theNeuronArray.GetNeuron(nID);
                if (MainWindow.useServers)
                {
                    sourceNeuron.synapses = NeuronClient.GetSynapses(sourceNeuron.id);
                }

                int    destId     = GetClipboardId(X1o, Y1o, nID);
                Neuron destNeuron = myClipBoard.GetNeuron(destId);
                destNeuron.Owner = myClipBoard;
                if (sourceNeuron.Synapses != null)
                {
                    foreach (Synapse s in sourceNeuron.Synapses)
                    {
                        //only copy synapses with both ends in the selection
                        if (neuronsToCopy.Contains(s.TargetNeuron))
                        {
                            destNeuron.AddSynapse(GetClipboardId(X1o, Y1o, s.TargetNeuron), s.Weight, s.model);
                        }
                        else
                        {
                            string targetName = MainWindow.theNeuronArray.GetNeuron(s.targetNeuron).label;
                            if (targetName != "")
                            {
                                boundarySynapsesOut.Add(new BoundarySynapse
                                {
                                    innerNeuronID = destNeuron.id,
                                    outerNeuronID = s.targetNeuron,
                                    weight        = s.weight,
                                    model         = s.model
                                });
                            }
                        }
                    }
                }
                if (sourceNeuron.SynapsesFrom != null)
                {
                    foreach (Synapse s in sourceNeuron.SynapsesFrom)
                    {
                        if (!neuronsToCopy.Contains(s.TargetNeuron))
                        {
                            string sourceName = MainWindow.theNeuronArray.GetNeuron(s.targetNeuron).label;
                            if (sourceName != "")
                            {
                                boundarySynapsesIn.Add(new BoundarySynapse
                                {
                                    innerNeuronID = destNeuron.id,
                                    outerNeuronID = s.targetNeuron,
                                    weight        = s.weight,
                                    model         = s.model
                                });;
                            }
                        }
                    }
                }
            }

            //copy modules
            foreach (ModuleView mv in MainWindow.theNeuronArray.modules)
            {
                if (theSelection.NeuronInSelection(mv.FirstNeuron) > 0 && theSelection.NeuronInSelection(mv.LastNeuron) > 0)
                {
                    ModuleView newMV = new ModuleView()
                    {
                        FirstNeuron = GetClipboardId(X1o, Y1o, mv.FirstNeuron),
                        TheModule   = mv.TheModule,
                        Color       = mv.Color,
                        Height      = mv.Height,
                        Width       = mv.Width,
                        Label       = mv.Label,
                        CommandLine = mv.CommandLine,
                    };

                    myClipBoard.modules.Add(newMV);
                }
            }
        }
Пример #16
0
        private void ButtonOK_Click(object sender, RoutedEventArgs e)
        {
            buttonOK.IsEnabled = false;
            MainWindow.CloseAllModuleDialogs();
            MainWindow.CloseHistoryWindow();
            MainWindow.CloseNotesWindow();
            if (MainWindow.theNeuronArray != null)
            {
                MainWindow.theNeuronArray.Modules.Clear();
            }
            MainWindow.arrayView.ClearSelection();
            MainWindow.theNeuronArray = new NeuronArray();

            if (!int.TryParse(textBoxColumns.Text, out cols))
            {
                return;
            }
            if (!int.TryParse(textBoxRows.Text, out rows))
            {
                return;
            }
            if (checkBoxSynapses.IsChecked == true)
            {
                doSynapses = true;
            }

            arraySize           = rows * cols;
            progressBar.Maximum = arraySize;

            int.TryParse(textBoxSynapses.Text, out synapsesPerNeuron);
            MainWindow.arrayView.Dp.NeuronDisplaySize = 62;
            MainWindow.arrayView.Dp.DisplayOffset     = new Point(0, 0);

            if (MainWindow.useServers)
            {
                //TODO: Replace this with a multicolumn UI
                MainWindow.theNeuronArray.Initialize(arraySize, rows);
                string[] lines = ServerList.Text.Split('\n');
                NeuronClient.serverList.Clear();
                foreach (string line in lines)
                {
                    if (line == "")
                    {
                        continue;
                    }
                    string[]            command = line.Split(' ');
                    NeuronClient.Server s       = new NeuronClient.Server();
                    s.ipAddress = IPAddress.Parse(command[0]);
                    s.name      = command[1];
                    int.TryParse(command[2], out s.firstNeuron);
                    int.TryParse(command[3], out s.lastNeuron);
                    NeuronClient.serverList.Add(s);
                }

                int totalNeuronsInServers = 0;
                for (int i = 0; i < NeuronClient.serverList.Count; i++)
                {
                    totalNeuronsInServers += NeuronClient.serverList[i].lastNeuron - NeuronClient.serverList[i].firstNeuron;
                }
                if (totalNeuronsInServers != arraySize)
                {
                    MessageBox.Show("Server neuron allocation does not equal total neurons!");
                    buttonOK.IsEnabled = true;
                    returnValue        = false;
                    return;
                }

                if (!doSynapses)
                {
                    synapsesPerNeuron = 0;
                }
                NeuronClient.InitServers(synapsesPerNeuron, arraySize);
                NeuronClient.WaitForDoneOnAllServers();
                returnValue = true;
                Close();
            }
            else
            {
                bgw.DoWork += AsyncCreateNeurons;
                bgw.RunWorkerAsync();

                barUpdateTimer.Tick += Dt_Tick;
                barUpdateTimer.Start();
            }
        }
Пример #17
0
        private void ButtonOK_Click(object sender, RoutedEventArgs e)
        {
            bool previousShowSynapses = false;

            if (MainWindow.theNeuronArray != null)
            {
                previousShowSynapses = MainWindow.theNeuronArray.ShowSynapses;
            }
            MainWindow.CloseAllModuleDialogs();
            MainWindow.CloseHistoryWindow();
            MainWindow.CloseNotesWindow();
            MainWindow.arrayView.ClearShowingSynapses();
            if (MainWindow.theNeuronArray != null)
            {
                lock (MainWindow.theNeuronArray.Modules)
                {
                    MainWindow.theNeuronArray.Modules.Clear();
                }
            }
            MainWindow.arrayView.ClearSelection();
            MainWindow.theNeuronArray = new NeuronArray();

            if (!int.TryParse(textBoxColumns.Text, out cols))
            {
                return;
            }
            if (!int.TryParse(textBoxRows.Text, out rows))
            {
                return;
            }
            if (cols <= 0)
            {
                return;
            }
            if (rows <= 0)
            {
                return;
            }
            //if (checkBoxSynapses.IsChecked == true) doSynapses = true;
            if (!int.TryParse(Refractory.Text, out refractory))
            {
                return;
            }

            arraySize = rows * cols;
            //progressBar.Maximum = arraySize;

            //int.TryParse(textBoxSynapses.Text, out synapsesPerNeuron);
            MainWindow.arrayView.Dp.NeuronDisplaySize = 62;
            MainWindow.arrayView.Dp.DisplayOffset     = new Point(0, 0);

            if (MainWindow.useServers && NeuronClient.serverList.Count > 0)
            {
                //TODO: Replace this with a multicolumn UI
                MainWindow.theNeuronArray.Initialize(arraySize, rows);
                string[] lines = ServerList.Text.Split('\n');
                NeuronClient.serverList.Clear();
                foreach (string line in lines)
                {
                    if (line == "")
                    {
                        continue;
                    }
                    string[]            command = line.Split(' ');
                    NeuronClient.Server s       = new NeuronClient.Server();
                    s.ipAddress = IPAddress.Parse(command[0]);
                    s.name      = command[1];
                    int.TryParse(command[2], out s.firstNeuron);
                    int.TryParse(command[3], out s.lastNeuron);
                    NeuronClient.serverList.Add(s);
                }

                int totalNeuronsInServers = 0;
                for (int i = 0; i < NeuronClient.serverList.Count; i++)
                {
                    totalNeuronsInServers += NeuronClient.serverList[i].lastNeuron - NeuronClient.serverList[i].firstNeuron;
                }
                if (totalNeuronsInServers != arraySize)
                {
                    MessageBox.Show("Server neuron allocation does not equal total neurons!");
                    buttonOK.IsEnabled = true;
                    returnValue        = false;
                    return;
                }

                NeuronClient.InitServers(0, arraySize);
                NeuronClient.WaitForDoneOnAllServers();
                returnValue = true;
                Close();
                returnValue = true;
            }
            else
            {
                GC.Collect(3, GCCollectionMode.Forced, true);
                MainWindow.theNeuronArray.Initialize(arraySize, rows);
                MainWindow.theNeuronArray.RefractoryDelay = refractory;

                MainWindow.theNeuronArray.ShowSynapses = previousShowSynapses;
                MainWindow.thisWindow.SetShowSynapsesCheckBox(previousShowSynapses);
                Close();
                returnValue = true;
            }
            MainWindow.theNeuronArray.LoadComplete = true;
        }