次のようなマトリックスを作成しました
00 node1 node2 node3
node1 0 1 0
node2 1 1 1
node3 0 0 0
でやることにしましたString[,] matrix
。次のコードで必要なマトリックスが得られることを願っていましたが、コンパイルすると、「ノード i」と「ノード j」のみが出力されます。
public AdjMatrix(ArrayList nodeList,ArrayList linkList)
{
String[,] matrix = new String [nodeList.Count,nodeList.Count];
ArrayList result = new ArrayList();
using (StreamWriter writer = new StreamWriter("C:\\Users\\Martina\\Desktop\\matrix.txt"))
{
Console.SetOut(writer);
//inizializzazione dei nomi delle classi
for (int i = 0; i < nodeList.Count; i++)
{
if (i == 0)
{
matrix[i,0]=("");
}
else
{
foreach (EA.Element node in nodeList)
{
matrix[i,0] = node.Name;
}
Console.WriteLine("la riga della matrice" + matrix[i,0]);
}
}
//inizializzazione dei valori della matrice
for (int j = 0; j < nodeList.Count; j++)
{
if (j==0)
{
matrix[0,j]=("");
}
else
{
foreach (EA.Element node in nodeList)
{
matrix[0,j] = node.Name;
}
Console.WriteLine("la riga della matrice" + matrix[0,j]);
}
}
//definizione dell'esistenza del link
foreach (EA.Connector link in linkList)
{
for (int i = 1; i < nodeList.Count; i++)
{
int supplier = link.SupplierID;
int client = link.ClientID;
String supplierNode = modelRepository.GetElementByID(supplier).Name;
String clientNode = modelRepository.GetElementByID(client).Name;
if (supplierNode.Equals((String)matrix[i,0]))
{
for (int j = 1; j < nodeList.Count; j++)
{
if (clientNode.Equals((String)matrix[0,j]))
{
matrix[i,j] = "1";
}
else
{
matrix[i,j] = "0";
}
}
}
}
}
Console.WriteLine("matrix : ");
for (int i = 0; i < nodeList.Count; i++)
{
for (int j = 0; j < nodeList.Count; j++)
Console.Write(matrix[i, j] + "\t");
Console.WriteLine();
}
}
}
少なくともノードの名前が表示されないのはなぜですか。間違いが見つからないのはなぜですか。なぜ機能しないのですか。ご協力ありがとうございました。
nodeListでは、文字列であるノードの名前を取得し、linkListには Connector 要素が含まれているため、クライアント要素とサプライヤー要素をノードと比較できます。