I been trying to fix my code for it to give me the right number of nodes within the netlist and it keeps getting one less node than what it actually is, this is the part of my code that reads and analyze the info from the file. I am going insane at this point ); ( I already asked ai to help me fix this issue and nothing)
Example:
netlist:
V1 1 0 5
R1 1 2 10
R2 2 0 2
output desired for matrix M:
1 0 0
0 1 0
0 0 1
output with my code :
1 0
0 1
// Define a struct to represent components in the netlist
struct Component {
string label;
int source_node;
int destination_node;
double value;
};
// Function to parse a line from the netlist file into a Component struct
Component parseComponent(const string& line) {
Component comp;
stringstream ss(line);
ss >> comp.label >> comp.source_node >> comp.destination_node >> comp.value;
return comp;
}
// Function to perform circuit analysis and write results to output file
void analyzeCircuit(const vector<Component>& components) {
// Find the number of nodes
int numNodes = 0;
for (const auto& comp : components) {
numNodes = max(numNodes, max(comp.source_node, comp.destination_node));
}
....
int main() {
vector<Component> components;
// Read netlist from file
ifstream inputFile("netlist.txt");
if (inputFile.is_open()) {
string line;
while (getline(inputFile, line)) {
// Parse each line of the netlist into a Component struct
components.push_back(parseComponent(line));
}
inputFile.close();
// Perform circuit analysis
analyzeCircuit(components);
} else {
cout << "Unable to open netlist.txt file." << endl;
}
return 0;
}