// n , range, max_range: global integers
// W[][]: global integer array
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) // Generate G
{ int i, j, k;
n = int::Parse(textBox1->Text);
range = int::Parse(textBox2->Text);
max_range = int::Parse(textBox3->Text);
W = new int * [n];
for(i = 0; i < n; i++)
W[i] = new int [n];
for (i=0; i<n; i++)
{ for (j=i+1; j<n; j++)
{ W[i][j] = rand()%range + 1;
if (W[i][j] > max_range) W[i][j] = LargeInt; // Control the density of edges in G
W[j][i] = W[i][j];
}
W[i][i] = LargeInt;
}
if (checkBox1->Checked)
{ dataGridView1->RowCount = n;
dataGridView1->ColumnCount = n;
// dataGridView1->AutoResizeColumns();
for (i=0; i<n; i++)
{ // dataGridView1->Rows[i]->HeaderCell->Value = i;
// dataGridView1->Columns[i]->HeaderCell->Value = i;
for (j=0; j<n; j++)
{ dataGridView1->Rows[i]->Cells[j]->Value = W[i][j];
}
}
}
}
// ==> Generating random numbers in [1, 100] with the constraint that those > 50 are set as 99999
// ==> Thus, about 50% entries (costs of edges in G) in the distance matrix are 99999.