Created
October 6, 2018 22:27
-
-
Save WillWetzelCMS/0b1fcd96efbfbd834ac3829f94efd207 to your computer and use it in GitHub Desktop.
Dessertation in Boolean Networks by Will Wetzel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<ItemGroup Label="ProjectConfigurations"> | |
<ProjectConfiguration Include="Debug|Win32"> | |
<Configuration>Debug</Configuration> | |
<Platform>Win32</Platform> | |
</ProjectConfiguration> | |
<ProjectConfiguration Include="Release|Win32"> | |
<Configuration>Release</Configuration> | |
<Platform>Win32</Platform> | |
</ProjectConfiguration> | |
<ProjectConfiguration Include="Debug|x64"> | |
<Configuration>Debug</Configuration> | |
<Platform>x64</Platform> | |
</ProjectConfiguration> | |
<ProjectConfiguration Include="Release|x64"> | |
<Configuration>Release</Configuration> | |
<Platform>x64</Platform> | |
</ProjectConfiguration> | |
</ItemGroup> | |
<ItemGroup> | |
<ClCompile Include="Entity.cpp" /> | |
<ClCompile Include="main.cpp" /> | |
<ClCompile Include="TruthTable.cpp" /> | |
</ItemGroup> | |
<ItemGroup> | |
<ClInclude Include="Entity.h" /> | |
<ClInclude Include="TruthTable.h" /> | |
</ItemGroup> | |
<ItemGroup> | |
<Text Include="input.txt" /> | |
<Text Include="input2.txt" /> | |
<Text Include="inputgate.txt" /> | |
</ItemGroup> | |
<PropertyGroup Label="Globals"> | |
<ProjectGuid>{EBD8011B-8A88-4A78-AE3E-8D044E887C0E}</ProjectGuid> | |
<RootNamespace>BooleanNetworkV3</RootNamespace> | |
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> | |
</PropertyGroup> | |
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |
<ConfigurationType>Application</ConfigurationType> | |
<UseDebugLibraries>true</UseDebugLibraries> | |
<PlatformToolset>v140</PlatformToolset> | |
<CharacterSet>MultiByte</CharacterSet> | |
</PropertyGroup> | |
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |
<ConfigurationType>Application</ConfigurationType> | |
<UseDebugLibraries>false</UseDebugLibraries> | |
<PlatformToolset>v140</PlatformToolset> | |
<WholeProgramOptimization>true</WholeProgramOptimization> | |
<CharacterSet>MultiByte</CharacterSet> | |
</PropertyGroup> | |
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | |
<ConfigurationType>Application</ConfigurationType> | |
<UseDebugLibraries>true</UseDebugLibraries> | |
<PlatformToolset>v140</PlatformToolset> | |
<CharacterSet>MultiByte</CharacterSet> | |
</PropertyGroup> | |
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | |
<ConfigurationType>Application</ConfigurationType> | |
<UseDebugLibraries>false</UseDebugLibraries> | |
<PlatformToolset>v140</PlatformToolset> | |
<WholeProgramOptimization>true</WholeProgramOptimization> | |
<CharacterSet>MultiByte</CharacterSet> | |
</PropertyGroup> | |
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | |
<ImportGroup Label="ExtensionSettings"> | |
</ImportGroup> | |
<ImportGroup Label="Shared"> | |
</ImportGroup> | |
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |
</ImportGroup> | |
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |
</ImportGroup> | |
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |
</ImportGroup> | |
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | |
</ImportGroup> | |
<PropertyGroup Label="UserMacros" /> | |
<PropertyGroup /> | |
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | |
<ClCompile> | |
<WarningLevel>Level3</WarningLevel> | |
<Optimization>Disabled</Optimization> | |
<SDLCheck>true</SDLCheck> | |
</ClCompile> | |
</ItemDefinitionGroup> | |
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |
<ClCompile> | |
<WarningLevel>Level3</WarningLevel> | |
<Optimization>Disabled</Optimization> | |
<SDLCheck>true</SDLCheck> | |
</ClCompile> | |
</ItemDefinitionGroup> | |
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |
<ClCompile> | |
<WarningLevel>Level3</WarningLevel> | |
<Optimization>MaxSpeed</Optimization> | |
<FunctionLevelLinking>true</FunctionLevelLinking> | |
<IntrinsicFunctions>true</IntrinsicFunctions> | |
<SDLCheck>true</SDLCheck> | |
</ClCompile> | |
<Link> | |
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |
<OptimizeReferences>true</OptimizeReferences> | |
</Link> | |
</ItemDefinitionGroup> | |
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |
<ClCompile> | |
<WarningLevel>Level3</WarningLevel> | |
<Optimization>MaxSpeed</Optimization> | |
<FunctionLevelLinking>true</FunctionLevelLinking> | |
<IntrinsicFunctions>true</IntrinsicFunctions> | |
<SDLCheck>true</SDLCheck> | |
</ClCompile> | |
<Link> | |
<EnableCOMDATFolding>true</EnableCOMDATFolding> | |
<OptimizeReferences>true</OptimizeReferences> | |
</Link> | |
</ItemDefinitionGroup> | |
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |
<ImportGroup Label="ExtensionTargets"> | |
</ImportGroup> | |
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<ItemGroup> | |
<Filter Include="Source Files"> | |
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | |
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | |
</Filter> | |
<Filter Include="Header Files"> | |
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | |
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> | |
</Filter> | |
<Filter Include="Resource Files"> | |
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | |
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | |
</Filter> | |
</ItemGroup> | |
<ItemGroup> | |
<ClCompile Include="main.cpp"> | |
<Filter>Source Files</Filter> | |
</ClCompile> | |
<ClCompile Include="TruthTable.cpp"> | |
<Filter>Source Files</Filter> | |
</ClCompile> | |
<ClCompile Include="Entity.cpp"> | |
<Filter>Source Files</Filter> | |
</ClCompile> | |
</ItemGroup> | |
<ItemGroup> | |
<ClInclude Include="TruthTable.h"> | |
<Filter>Header Files</Filter> | |
</ClInclude> | |
<ClInclude Include="Entity.h"> | |
<Filter>Header Files</Filter> | |
</ClInclude> | |
</ItemGroup> | |
<ItemGroup> | |
<Text Include="input.txt"> | |
<Filter>Source Files</Filter> | |
</Text> | |
<Text Include="inputgate.txt"> | |
<Filter>Source Files</Filter> | |
</Text> | |
<Text Include="input2.txt"> | |
<Filter>Source Files</Filter> | |
</Text> | |
</ItemGroup> | |
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Name: Will Wetzel - 130251255 | |
#include <iostream> | |
#include <fstream> | |
#include <istream> | |
#include <string> | |
#include <algorithm> | |
#include <vector> | |
#include "Entity.h" | |
using namespace std; | |
Entity::Entity(char n, vector<char> net, TruthTable table) { | |
name = n; | |
edges = net; | |
table = TruthTable(edges.size()); | |
state = 0; | |
inputs = edges.size(); | |
} | |
Entity::Entity() { | |
table = new TruthTable(3); | |
state = 0; | |
} | |
Entity::Entity(char n, int size) { | |
name = n; | |
table = new TruthTable(size); | |
state = 0; | |
} | |
/* | |
Entity::Entity(Entity& Entity) { | |
if (this != &Entity) | |
*this = Entity; | |
} | |
*/ | |
Entity::~Entity() { | |
//Nothing to do here \o.o/ | |
//delete table; | |
} | |
//Unused - Populates 1 Entity | |
void Entity::populateEntity(string fname) { | |
ifstream file; | |
file.open(fname); | |
if (file.is_open()) { | |
cout << "File opened successfully.Reading data to entity and array" << endl; | |
while (!file.eof()) { | |
file >> name; //Set name | |
cout << "name: " << name << endl; | |
//Reading in network | |
string tmp; | |
file >> tmp; | |
for (int i = 0; i < tmp.length(); i++) { | |
edges[i] = tmp[i]; | |
cout << "network: " << edges[i] << endl; | |
//file >> tmp; | |
} | |
cout << "Cols and Rows" << table->getCols() << table->getRows() << endl; | |
//Reading into table | |
for (int i = 0; i < table->getRows(); i++) { | |
string row; | |
if (file >> row) { | |
for (int j = 0; j != std::min<int>(table->getCols(), row.length()); ++j) { | |
table->setPos(i, j, row[j] - 0x30); | |
} | |
cout << row << endl; | |
} | |
else break; | |
} | |
cout << "End of Loop" << endl; | |
} | |
} | |
file.close(); | |
} | |
void Entity::printTable() { | |
for (int i = 0; i < table->getRows(); i++) { | |
for (int j = 0; j < table->getCols(); j++) { | |
cout << "(" << i << "," << j << ") : " << table->getPos(i, j) << " "; | |
} | |
cout << endl; | |
} | |
} | |
/*Cout Overload - Prints input and output of Entity*/ | |
std::ostream& operator<< (std::ostream& outStream, Entity entity) { | |
outStream << "Name: " << entity.getName() << " - Outputs: " << entity.getInputs() << " - State: " << | |
entity.getState() << endl; | |
return outStream; | |
} | |
Entity& Entity::operator=(Entity rhs) { | |
if (this == &rhs) { | |
return *this; | |
} | |
edges = rhs.edges; | |
inputs = rhs.inputs; | |
state = rhs.state; | |
table = rhs.table; | |
return *this; | |
} | |
//bool Entity::operator==(Entity& lhs, Entity &rhs) { | |
// return lhs.name == rhs.name; | |
//} | |
/* | |
//Working read in method for setting up one node | |
void Entity::populateEntity(string fname) { | |
ifstream file; | |
file.open(fname); | |
if (file.is_open()) { | |
cout << "File opened successfully.Reading data to entity and array" << endl; | |
while (!file.eof()) { | |
file >> name; //Set name | |
cout << "name: " << name << endl; | |
//Reading in network | |
string tmp; | |
file >> tmp; | |
for (int i = 0; i < tmp.length(); i++) { | |
network[i] = tmp[i]; | |
cout << "network: " << network[i] << endl; | |
//file >> tmp; | |
} | |
cout << "Cols and Rows" << table->getCols() << table->getRows() << endl; | |
//Reading into table | |
for (int i = 0; i < table->getRows(); i++) { | |
string row; | |
if (file >> row) { | |
for (int j = 0; j != std::min<int>(table->getCols(), row.length()); ++j) { | |
table->setPos(i, j, row[j] - 0x30); | |
} | |
cout << row << endl; | |
} | |
else break; | |
} | |
cout << "End of Loop" << endl; | |
} | |
} | |
file.close(); | |
} | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Name: Will Wetzel - 130251255 | |
#pragma once | |
#include <iostream> | |
#include <string> | |
#include "TruthTable.h" | |
using namespace std; | |
class Entity { | |
public: | |
Entity(char, vector<char>, TruthTable table); //Constructor | |
Entity(); | |
Entity(char name, int size); | |
//Entity(Entity&); //Copy Constructor | |
~Entity(); //Destructor | |
void populateEntity(string); | |
void printTable(); | |
//Getters | |
inline char getName() { | |
return name; | |
} | |
inline int getInputs() { | |
return edges.capacity(); | |
} | |
inline char getEdges(int i) { | |
return edges[i]; | |
} | |
inline int getState() { | |
return state; | |
} | |
//Setters | |
inline void setName(char n) { | |
name = n; | |
} | |
inline void setEdges(char n) { | |
edges.push_back(n); | |
} | |
inline void setInputs(int n) { | |
inputs = n; | |
} | |
inline void setState(int s) { | |
state = s; | |
} | |
//Setter for state? | |
/*cout override*/ | |
friend std::ostream& operator<< (std::ostream& outStream, Entity entity); | |
/*Operator= override*/ | |
Entity& operator=(Entity rhs); | |
public: | |
char name; | |
vector<char> edges; | |
int inputs; | |
int state = 0; | |
TruthTable* table; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 0 0 | |
1 0 0 | |
0 1 0 | |
1 1 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 0 0 0 | |
1 0 0 0 | |
0 1 0 0 | |
0 0 1 0 | |
1 1 0 0 | |
1 0 1 0 | |
1 1 1 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 | |
AB | |
A | |
B | |
01 | |
10 | |
B | |
A | |
01 | |
10 | |
END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Name: Will Wetzel - 130251255 | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <algorithm> | |
#include <vector> | |
#include <array> | |
#include "Entity.h" | |
using namespace std; | |
vector<Entity> populateNetwork(string fname); | |
vector<Entity> cycleNetwork(vector<Entity> network); | |
void printNetwork(vector<Entity> network); | |
void printStates(vector<Entity> network); | |
bool compareNetworkStates(vector<int> startingStates, vector<int> newStates); | |
int main() { | |
int COL = 3; //Need to edit TruthTable class to take inputs, not number of columns expected | |
TruthTable table(COL); | |
table.printTable(); | |
cout << "Testing populate" << endl; | |
table.populateTable("input.txt"); | |
table.printTable(); | |
cout << "Testing fetch method" << endl; | |
cout << "Fetching inputs 1, 0: " << endl; | |
cout << table.fetch(1, 0) << endl; | |
cout << "Fetching inputs 1, 1: " << endl; | |
cout << table.fetch(1, 1) << endl << endl; | |
//TODO: Change Fetch function to recieve multiple inputs | |
//Testing varadic function implementation - | |
/* | |
cout << "**************** Testing Array Fetch Function *****************" << endl; | |
TruthTable tab2(4); | |
tab2.populateTable("input2.txt"); | |
tab2.printTable(); | |
cout << "Fetch 111 : "; | |
int vals3[3] = { 1, 1, 1 }; | |
cout << tab2.fetch(vals3) << endl; | |
*/ | |
//Testing Entity | |
cout << endl << "************ Testing Network methods **************" << endl; | |
vector<Entity> network = populateNetwork("inputgate.txt"); | |
cout << endl << "************ Printing Network Details ****************" << endl; | |
printNetwork(network); | |
//Testing Traces | |
cout << endl << "************* Testing Traces *************" << endl; | |
//printStates(network); | |
network = cycleNetwork(network); | |
//printStates(network); | |
getchar(); | |
getchar(); | |
return 0; | |
} | |
vector<Entity> populateNetwork(string fname) { | |
ifstream file; | |
file.open(fname); | |
if (file.is_open()) { | |
cout << "File opened successfully.Reading data to entity and array" << endl; | |
string tmp; | |
int size; | |
file >> size; | |
file >> tmp; | |
vector<Entity> network; | |
for (int i = 0; i < size; i++) { | |
network.push_back(Entity(tmp[i], size)); | |
} | |
for (int i = 0; i < network.size(); i++) { | |
//Add in check to check network[i] name with name in file? | |
if (i == 0) { | |
file >> tmp; | |
} | |
if (tmp[0] != network[i].getName()) { | |
cout << "ERROR: Please check input text file." << endl; | |
exit(0); | |
} | |
//network[i].setName(tmp[0]); //Set name | |
cout << "name: " << network[i].getName() << endl; | |
//Reading in network | |
string tmpedges; | |
file >> tmpedges; | |
for (int j = 0; j < tmpedges.length(); j++) { | |
network[i].setEdges(tmpedges[j]); | |
cout << "network: " << network[i].getEdges(j) << endl; | |
//file >> tmp; | |
} | |
cout << "Cols and Rows" << network[i].table->getCols() << network[i].table->getRows() << endl; | |
//Setting inputs | |
int numEdges = 0; | |
numEdges = tmpedges.length(); | |
network[i].setInputs(numEdges); | |
//Reading into table | |
for (int j = 0; j < network[i].table->getRows(); j++) { | |
if (file >> tmp) { | |
TABLEPOPULATE: | |
for (int k = 0; k != std::min<int>(network[i].table->getCols(), tmp.length()); ++k) { | |
network[i].table->setPos(j, k, tmp[k] - 0x30); | |
cout << network[i].table->getPos(j, k); | |
} | |
cout << endl; | |
j++; //Manual increment because of goto label (increment column access by 1) | |
} | |
else break; | |
file >> tmp; | |
if ((tmp[0] == '0' || '1') && !((tmp[0] <= 'z' && tmp[0] >= 'a') || (tmp[0] <= 'Z' && tmp[0] >= 'A'))) { | |
goto TABLEPOPULATE; | |
} | |
else if (!file.eof()) { | |
break; | |
} | |
else { | |
return network; | |
file.close(); | |
} | |
} | |
} | |
} | |
} | |
vector<Entity> cycleNetwork(vector<Entity> network) { | |
vector<int> newStates; | |
vector<int> startingStates; | |
/*Save starting states to vector - For finding attractor later*/ | |
for (int i = 0; i < network.size(); i++) { | |
startingStates.push_back(network[i].getState()); | |
} | |
/*Print states of nodes in Network*/ | |
cout << "Starting states of Network:" << endl; | |
printStates(network); | |
do { | |
//Clear newStates | |
newStates.clear(); | |
//For loop to cycle through Network Nodes | |
for (int nodeNum = 0; nodeNum < network.size(); nodeNum++) { | |
vector<Entity> edges; | |
//Loop for edges of current Node. | |
for (int edgeNum = 0; edgeNum < network[nodeNum].getInputs(); edgeNum++) { | |
char tmpEdge = network[nodeNum].getEdges(edgeNum); | |
//Finding Edge in vector and storing if found, else end program | |
for (int i = 0; i < network.capacity(); i++) { | |
if (network[i].getName() == tmpEdge) { | |
//Edge found, add to vector | |
edges.push_back(network[i]); | |
} | |
} | |
if (edges.size() == 0) { | |
//Edge not found in Network, check inputs and retry | |
cout << "Edge not found in Network, please check input file." << endl; | |
exit(0); | |
} | |
} | |
//Edges have been found in Network. Now find State for next stage of Trace. | |
//Loop through Vector and gather all states: | |
int* states; | |
int size = edges.size(); | |
states = new int[size]; | |
for (int i = 0; i < edges.size(); i++) { | |
states[i] = edges[i].getState(); | |
} | |
int fetchresult; | |
for (int edgeNum = 0; edgeNum < edges.size(); edgeNum++) { | |
fetchresult = edges[edgeNum].table->fetch(states[0]); | |
} | |
//Create new Vector of newNetwork | |
newStates.push_back(fetchresult); | |
delete[] states; | |
} | |
for (int i = 0; i < newStates.size(); i++) { | |
network[i].setState(newStates[i]); | |
} | |
printStates(network); | |
} while (compareNetworkStates(startingStates, newStates) != true); | |
/*Print final states of Network before returning*/ | |
cout << "Final state of Network" << endl; | |
printStates(network); | |
return network; | |
} | |
/* | |
* Working line of find_if, keeping for prosperity: | |
* auto it = find_if(network.begin(), network.end(), [&tmpEdge](Entity& ob) {return ob.getName() == tmpEdge;}); | |
*/ | |
bool compareNetworkStates(vector<int> startingStates, vector<int> newStates) { | |
for (int i = 0; i < startingStates.size(); i++) { | |
if (startingStates[i] != newStates[i]) { | |
return false; | |
} | |
else { | |
return true; | |
} | |
} | |
} | |
void printNetwork(vector<Entity> network) { | |
int size = network.size(); | |
cout << "Network print out" << endl; | |
for (int i = 0; i < size; i++) { | |
cout << "Entity " << i + 1 << endl; | |
cout << "Name: " << network[i].getName() << endl; | |
int inSize = network[i].getInputs(); | |
for (int j = 0; j < inSize; j++) { | |
cout << "Edges: " << network[i].getEdges(j) << endl; | |
} | |
cout << "State: " << network[i].getState() << endl; | |
cout << "TruthTable: " << endl; | |
network[i].printTable(); | |
cout << endl; | |
} | |
} | |
void printStates(vector<Entity> network) { | |
for (int nodeCount = 0; nodeCount < network.size(); nodeCount++) { | |
cout << "Entity name: " << network[nodeCount].getName() << " - State: " << network[nodeCount].getState() << endl; | |
} | |
} | |
/* | |
**** Asynchonus cyclenetwork Method *************** | |
vector<Entity> cycleNetwork(vector<Entity> network) { | |
vector<Entity> newNetwork; | |
//For loop to cycle through Network Nodes | |
for (int nodeNum = 0; nodeNum < network.size(); nodeNum++) { | |
vector<Entity> edges; | |
//Loop for edges of current Node. | |
for (int edgeNum = 0; edgeNum < network[nodeNum].getInputs(); edgeNum++) { | |
char tmpEdge = network[nodeNum].getEdges(edgeNum); | |
//Finding Edge in vector and storing if found, else end program | |
for (int i = 0; i < network.capacity(); i++) { | |
if (network[i].getName() == tmpEdge) { | |
//Edge found, add to vector | |
edges.push_back(network[i]); | |
} | |
} | |
if (edges.size() == 0) { | |
//Edge not found in Network, check inputs and retry | |
cout << "Edge not found in Network, please check input file." << endl; | |
exit(0); | |
} | |
} | |
//Edges have been found in Network. Now find State for next stage of Trace. | |
//Loop through Vector and gater all states: | |
int* states; | |
int size = edges.size(); | |
states = new int[size]; //Must delete states!! | |
for (int i = 0; i < edges.size(); i++) { | |
states[i] = edges[i].getState(); | |
} | |
//TODO: CREATE VECTOR OF EDGE STATES (OR SOMETHING) TO SEND TO FETCH | |
//Change states/setState to array later for pasing to Fetch | |
int fetchresult; | |
for (int edgeNum = 0; edgeNum < edges.size(); edgeNum++) { | |
fetchresult = edges[edgeNum].table->fetch(states[0]); | |
} | |
//Create new Vector of newNetwork | |
newNetwork.push_back(fetchresult); | |
//network[nodeNum].setState(fetchresult); | |
delete[] states; | |
} | |
for (int i = 0; i < newNetwork.size(); i++) { | |
network[i].setState(newNetwork[i]); | |
} | |
return network; | |
} | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Name: Will Wetzel - 130251255 | |
#include <iomanip> | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <limits> | |
#include <vector> | |
#include "TruthTable.h" | |
#define NOMINMAX | |
using namespace std; | |
TruthTable::TruthTable(const int x) { | |
colCount = x; | |
rowCount = pow(2, x - 1); | |
//Create table - Array of Pointers | |
table = new int*[rowCount]; | |
for (int i = 0; i < rowCount; i++) { | |
table[i] = new int[colCount]; //Each pointer points to another array. | |
} | |
//Initialize all elements to 0. | |
for (int i = 0; i < rowCount; i++) { | |
for (int j = 0; j < colCount; j++) { | |
table[i][j] = 0; | |
} | |
} | |
//table[height][width] | |
cout << "Making TruthTable" << endl; | |
} | |
TruthTable::TruthTable(const TruthTable& table) { | |
if (this != &table) | |
*this = table; | |
} | |
TruthTable::~TruthTable() { | |
for (int i = 0; i < rowCount; i++) { | |
delete[] table[i]; | |
} | |
delete[] table; | |
cout << "Table deleted" << endl; | |
} | |
/*Fetches state for 2 col table*/ | |
int TruthTable::fetch(int val1) { | |
for (int row = 0; row < getRows(); row++) { | |
if ((table[row][0] == val1)) { | |
return table[row][1]; | |
} | |
} | |
} | |
/*Provided 2 values, will search table for result*/ | |
int TruthTable::fetch(int val1, int val2) { | |
for (int row = 0; row < getRows(); row++) { | |
if ((table[row][0] == val1) && (table[row][1] == val2)) { | |
return table[row][2]; | |
} | |
} | |
} | |
/* | |
int TruthTable::fetch(int vals[]) { | |
int rowMax = getRows(); | |
int valCount = 0; | |
int colMax = getCols() - 1; | |
int row = 0; | |
if (valCount != 0) { | |
Start: | |
valCount++; | |
} | |
for (row; row < rowMax; row++) { | |
for (valCount; valCount < colMax;) { | |
for (valCount; valCount < sizeof(vals);) { | |
if (vals[valCount] == table[row][valCount]) { | |
if (valCount == sizeof(vals)) { | |
return | |
} | |
goto Start; | |
} | |
} | |
} | |
} | |
*/ | |
/* | |
** Working for 2 cols | |
int TruthTable::fetch(int val1, int val2) { | |
for (int row = 0; row < getRows(); row++) { | |
if ((table[row][0] == val1) && (table[row][1] == val2)) { | |
return table[row][2]; | |
} | |
} | |
} | |
*/ | |
/*Prints truthtable to console*/ | |
void TruthTable::printTable() { | |
for (int i = 0; i < getRows(); i++) { | |
for (int j = 0; j < getCols(); j++) { | |
cout << "(" << i << "," << j << ") : " << table[i][j] << " "; | |
} | |
cout << endl; | |
} | |
} | |
void TruthTable::populateTable(string filename) { | |
//Solution 1 | |
/* | |
ifstream file("Load/infile.txt"); | |
for (int i = 0; i < rowCount; i++) { | |
string row; | |
if (file >> row) { | |
for (int j = 0; i != min<int>(colCount, row.length()); ++j) { | |
table[i][j] = row[j] - 0x30; | |
} | |
cout << row << endl; | |
} | |
else break; | |
} | |
*/ | |
//Solution 2: | |
ifstream file; | |
file.open(filename); | |
if (file.is_open()) { | |
cout << "file opened successfully.Reading data to array" << endl; | |
//if (cin.fail()) { | |
while (!file.eof()) { | |
for (int i = 0; i < rowCount; i++) { | |
for (int j = 0; j < colCount; j++) { | |
file >> table[i][j]; | |
// cout << table[i][j]; | |
} | |
cout << endl; | |
} | |
} | |
//} | |
} | |
file.close(); | |
} | |
void TruthTable::clearTable() { | |
for (int i = 0; i < rowCount; i++) { | |
for (int j = 0; j < colCount; j++) { | |
table[j][i] = 0; | |
} | |
} | |
} | |
/*Cout Overload - Prints input and output of table*/ | |
/* | |
std::ostream& operator<< (std::ostream& outStream, TruthTable tab) { | |
for (int i = 0; i < tab.rowCount; i++) { | |
for (int j = 0; j < tab.colCount; j++) { | |
cout << tab.table[i][j]; | |
} | |
cout << endl; | |
} | |
} | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Name: Will Wetzel - 130251255 | |
#pragma once | |
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
class TruthTable { | |
public: | |
TruthTable(const int x = 0); //Constructor | |
TruthTable(const TruthTable& t); //Copy Constructor | |
~TruthTable(); //Destructor | |
int fetch(int); | |
int fetch(int, int); | |
void printTable(); | |
void populateTable(string); | |
void clearTable(); | |
//Getters | |
inline int getCols() { return colCount; } | |
inline int getRows() { return rowCount; } | |
inline int getPos(int row, int col) { return table[row][col]; } | |
//Setters | |
inline void setPos(int row, int col, int n) { | |
table[row][col] = n; | |
} | |
/*cout override*/ | |
//friend std::ostream& operator<< (std::ostream& outStream, TruthTable table); | |
public: | |
int colCount; | |
int rowCount; | |
int** table; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment