Knight's Tour Generator
Tourneys and the Fast Generation and Obfuscation of Closed Knight's Tours
NeuralNet.cpp
Go to the documentation of this file.
1 
4 // MIT License
5 //
6 // Copyright (c) 2019 Ian Parberry
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 
26 #include "NeuralNet.h"
27 
29 // CNeuron functions.
30 
35 
37  CEdge(p0, p1, index){
38 } //constructor
39 
42 
44  return m_nState;
45 } //GetState
46 
50 
52  return m_nOldState == m_nState;
53 } //GetOldState
54 
57 
58 void CNeuron::SetState(int n){
60  m_nState = n;
61 } //SetState
62 
65 
67  return m_bOutput;
68 } //GetOutput
69 
72 
73 void CNeuron::SetOutput(bool b){
74  m_bOutput = b;
75 } //SetOutput
76 
78 // CNeuralNet functions.
79 
84 
86  ::srand(seed); //seed the default PRNG
87  m_cRandom.srand(); //seed our PRNG
88 } //constructor
89 
98 
100  if(i >= m_nNumVerts || j >= m_nNumVerts || i == j)return; //bail out
101 
102  CVertex* p0 = &m_pVertexList[i]; //first vertex
103  CVertex* p1 = &m_pVertexList[j]; //second vertex
104 
105  CNeuron* pEdge = new CNeuron(p0, p1, m_nNumEdges++); //edge between them
106 
107  m_vEdgeList.push_back(pEdge); //append edge to edge list
108  p0->InsertAdjacency(pEdge); //append edge to adjacency list of first vertex
109  p1->InsertAdjacency(pEdge); //append edge to adjacency list of second vertex
110 } //InsertNeuron
int GetState()
Get neuron state.
Definition: NeuralNet.cpp:43
UINT m_nNumEdges
Number of edges.
Definition: Graph.h:105
void SetOutput(bool b)
Set neuron output.
Definition: NeuralNet.cpp:73
bool GetOutput()
Get neuron output.
Definition: NeuralNet.cpp:66
CRandom m_cRandom
Random number generator.
Definition: Graph.h:112
Neuron in a Hopfield network.
Definition: NeuralNet.h:41
Header for CNeuralNet and its edges CNeuron.
int m_nState
Neuron state.
Definition: NeuralNet.h:43
std::vector< CEdge * > m_vEdgeList
Edge list.
Definition: Graph.h:104
unsigned int UINT
Abbreviation for unsigned integer.
Definition: Defines.h:84
void InsertAdjacency(CEdge *pEdge)
Add an edge to the edge list.
Definition: Graph.cpp:92
Undirected multi-graph.
Definition: Graph.h:102
CNeuron(CVertex *p0, CVertex *p1, UINT index)
Constructor.
Definition: NeuralNet.cpp:36
void SetState(int n)
Get neuron state.
Definition: NeuralNet.cpp:58
bool IsStable()
Stability test.
Definition: NeuralNet.cpp:51
Graph vertex.
Definition: Graph.h:70
CNeuralNet(UINT n, int seed)
Constructor.
Definition: NeuralNet.cpp:85
UINT m_nNumVerts
Number of vertices.
Definition: Graph.h:108
void srand()
Seed the random number generator.
Definition: Random.cpp:39
void InsertNeuron(UINT i, UINT j)
Insert a neuron.
Definition: NeuralNet.cpp:99
Graph edge.
Definition: Graph.h:41
int m_bOutput
Neuron output.
Definition: NeuralNet.h:45
int m_nOldState
Old neuron state.
Definition: NeuralNet.h:44
CVertex * m_pVertexList
Vertex list.
Definition: Graph.h:107