Skip to content

Commit

Permalink
Update GeneralResources.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKuz1001 authored Dec 8, 2019
1 parent b5fc644 commit b5d4a68
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions Task02/GeneralResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ public class Graph
public int graphAmountVertexes;
static int NumberOfConventionalUnitsInTotal = 1000000;

public Graph(int n, int m, int minWeight, int maxWeight)
public Graph(int amountVertexes, int approximateAmountEdges, int minWeight, int maxWeight)
{
graphAmountVertexes = n;
graphMatrix = new int[n, n];
graphAmountVertexes = amountVertexes;
graphMatrix = new int[amountVertexes, amountVertexes];
Random random = new Random();
int partAmountEdgesFromMax = (int)((long)m * NumberOfConventionalUnitsInTotal / (n * (n - 1) / 2));
m = 0;
for (int i = 0; i < n; i++)
int partAmountEdgesFromMax = (int)((long)approximateAmountEdges * NumberOfConventionalUnitsInTotal /
(amountVertexes * (amountVertexes - 1) / 2));
int exectAmountEdges = 0;
for (int i = 0; i < amountVertexes; i++)
{
for (int j = i + 1; j < n; j++)
for (int j = i + 1; j < amountVertexes; j++)
{
if (random.Next(NumberOfConventionalUnitsInTotal) < partAmountEdgesFromMax)
{
int weight = random.Next(minWeight, maxWeight);
graphMatrix[i, j] = graphMatrix[j, i] = weight;
m++;
exectAmountEdges++;
}
else
{
Expand All @@ -35,11 +36,11 @@ public Graph(int n, int m, int minWeight, int maxWeight)
}
}

graphListEdges = new (int, int, int)[m];
graphListEdges = new (int, int, int)[exectAmountEdges];
int k = 0;
for (int i = 0; i < n; i++)
for (int i = 0; i < amountVertexes; i++)
{
for (int j = i + 1; j < n; j++)
for (int j = i + 1; j < amountVertexes; j++)
{
if (graphMatrix[i, j] != INF)
{
Expand All @@ -50,8 +51,8 @@ public Graph(int n, int m, int minWeight, int maxWeight)
}

StreamWriter foutMatrix = new StreamWriter("matrix.txt");
foutMatrix.Write($"{n} {m}\n");
for (k = 0; k < m; k++)
foutMatrix.Write($"{amountVertexes} {exectAmountEdges}\n");
for (k = 0; k < exectAmountEdges; k++)
{
foutMatrix.Write($"{graphListEdges[k].Item2 + 1} " +
$"{graphListEdges[k].Item3 + 1} " +
Expand Down

0 comments on commit b5d4a68

Please sign in to comment.