I have a program which reads data from a file and creates nodes for a graph by using that data. Problem is, from a file of 4 lines, my program creates only two nodes (one line should create one node). Text file looks like this:
A/0/0.7
C/1/0/0.1 0.4
B/1/0/0.6 0.8
D/2/2 1/0.6 0.7 0.1 0.2
The structure of the Node data (it is a Bayesian Network) :
Node name / Number of parents / Parents' indexes in the file / Probabilities
using (StreamReader reader = new StreamReader(file))
{
while ((line = reader.ReadLine()) != null)
{
line = reader.ReadLine();
string name = "";
List<int> parents = new List<int>();
List<float> probs = new List<float>();
string[] splitLine = line.Split('/');
Console.WriteLine("splitLine array: ");
foreach (string item in splitLine)
{
Console.WriteLine(item);
}
Console.WriteLine();
int index = 2;
name = splitLine[0];
if (splitLine.Length == 4)
{
string[] temp = splitLine[2].Split(' ');
foreach (string item in temp)
parents.Add(Int32.Parse(item));
index = 3;
}
string[] temp1 = splitLine[index].Split(' ');
foreach (string item in temp1)
probs.Add(float.Parse(item, CultureInfo.InvariantCulture.NumberFormat));
Node newNode = new Node(name, parents, probs);
graph.Add(newNode);
}
}
If Node constructor gets called, program prints what data the new node has. I expect it to print:
Created Node:
Name: A
Parents' indexes: 0
Probabilities: 0.7
Created Node:
Name: C
Parents' indexes: 0
Probabilities: 0.1 0.4
Created Node:
Name: B
Parents' indexes: 0
Probabilities: 0.6 0.8
Created Node:
Name: D
Parents' indexes: 2 1
Probabilities: 0.6 0.7 0.1 0.2
But I get:
Created Node:
Name: C
Parents' indexes: 0
Probabilities: 0.1 0.4
Created Node:
Name: D
Parents' indexes: 2 1
Probabilities: 0.6 0.7 0.1 0.2