|
|
@ -11,131 +11,142 @@ namespace linear |
|
|
|
{ |
|
|
|
{ |
|
|
|
static void Main(string[] args) |
|
|
|
static void Main(string[] args) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Рандомное заплонение матрицы с количеством деталей pCount и количеством рабочих процессов workCount |
|
|
|
Random rnd = new Random(); |
|
|
|
Random rnd = new Random(); |
|
|
|
int pCount = 2; |
|
|
|
int pCount = 2; |
|
|
|
int workCount = 3; |
|
|
|
int workCount = 3; |
|
|
|
|
|
|
|
|
|
|
|
double[,] matrix = new double[workCount + 2, pCount + 1]; |
|
|
|
double[,] matrix = new double[workCount + 2, pCount + 1]; |
|
|
|
|
|
|
|
|
|
|
|
//for(int i = 0; i < workCount + 1; i++) |
|
|
|
for (int i = 0; i < workCount + 1; i++) |
|
|
|
//{ |
|
|
|
{ |
|
|
|
// for (int j = 0; j < pointCount; j++) matrix[i, j] = rnd.Next(1, 7); |
|
|
|
for (int j = 0; j < pCount; j++) matrix[i, j] = rnd.Next(1, 7); |
|
|
|
//} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//for (int i = 0; i < workCount + 1; i++) matrix[i, 2] = rnd.Next(1000, 4000); |
|
|
|
for (int i = 0; i < workCount; i++) matrix[i, 2] = rnd.Next(1000, 4000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
matrix[0, 0] = 2; |
|
|
|
//matrix[0, 0] = 2; |
|
|
|
matrix[0, 1] = 3; |
|
|
|
//matrix[0, 1] = 3; |
|
|
|
matrix[1, 0] = 3; |
|
|
|
//matrix[1, 0] = 3; |
|
|
|
matrix[1, 1] = 2; |
|
|
|
//matrix[1, 1] = 2; |
|
|
|
matrix[2, 0] = 1; |
|
|
|
//matrix[2, 0] = 1; |
|
|
|
matrix[2, 1] = 3; |
|
|
|
//matrix[2, 1] = 3; |
|
|
|
matrix[3, 0] = 5; |
|
|
|
//matrix[3, 0] = 5; |
|
|
|
matrix[3, 1] = 4; |
|
|
|
//matrix[3, 1] = 4; |
|
|
|
matrix[0, 2] = 2000; |
|
|
|
//matrix[0, 2] = 2000; |
|
|
|
matrix[1, 2] = 2000; |
|
|
|
//matrix[1, 2] = 2000; |
|
|
|
matrix[2, 2] = 1000; |
|
|
|
//matrix[2, 2] = 2000; |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < workCount + 1; i++) |
|
|
|
for (int i = 0; i < workCount + 1; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (int j = 0; j < pCount + 1; j++) Write(matrix[i, j] + " "); |
|
|
|
for (int j = 0; j < pCount + 1; j++) Write(matrix[i, j] + " "); |
|
|
|
WriteLine(); |
|
|
|
WriteLine(); |
|
|
|
} |
|
|
|
} |
|
|
|
WriteLine("\n\n"); |
|
|
|
WriteLine(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Point> debug = new List<Point>(); |
|
|
|
List<Point> Points = new List<Point>(); |
|
|
|
List<Point> Points = new List<Point>(); //лист точек пересечения прямых с осью координат и друг с другом |
|
|
|
double xMin = 0, yMin = 0; |
|
|
|
double xMin = matrix[0, 2] / matrix[0, 0], yMin = matrix[0, 2] / matrix[0, 1]; |
|
|
|
int indexMinX = 1, indexMinY = 1; |
|
|
|
double xRes, yRes; //индексы на случай, что на одной оси не одна минимальная точка |
|
|
|
for(int i = 0; i < workCount; i++) |
|
|
|
int indexMinX = 1, indexMinY = 1; //значения и индекс прямых, у которых минимальные значения пересечений с осями координат |
|
|
|
|
|
|
|
for (int i = 0; i < workCount; i++) //заполнение листа точками пересечения с осями координат и нахождение минимальных |
|
|
|
{ |
|
|
|
{ |
|
|
|
Points.Add(new Point |
|
|
|
if (xMin > matrix[i, 2] / matrix[i, 0]) |
|
|
|
{ |
|
|
|
|
|
|
|
Y = matrix[i, 2] / matrix[i, 1], |
|
|
|
|
|
|
|
X = matrix[i, 2] / matrix[i, 0], |
|
|
|
|
|
|
|
Line = i + 1 |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (i == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
xMin = Points[0].X; |
|
|
|
|
|
|
|
yMin = Points[0].Y; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (xMin > Points[i].X) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
xMin = Points[i].X; |
|
|
|
xMin = matrix[i, 2] / matrix[i, 0]; |
|
|
|
indexMinX = i + 1; |
|
|
|
indexMinX = i + 1; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (yMin > Points[i].Y) |
|
|
|
else if (xMin == matrix[i, 2] / matrix[i, 0]) xRes = i + 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (yMin > matrix[i, 2] / matrix[i, 1]) |
|
|
|
{ |
|
|
|
{ |
|
|
|
yMin = Points[i].Y; |
|
|
|
yMin = matrix[i, 2] / matrix[i, 1]; |
|
|
|
indexMinY = i + 1; |
|
|
|
indexMinY = i + 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (yMin == matrix[i, 2] / matrix[i, 1]) yRes = i + 1; |
|
|
|
|
|
|
|
|
|
|
|
foreach (Point p in Points) WriteLine("{0:00.00} {1:00.00}", p.X, p.Y); |
|
|
|
|
|
|
|
Write("\n\n"); |
|
|
|
|
|
|
|
WriteLine("X: {0:0.0} {2} \nY: {1:0.0} {3}\n\n", xMin, yMin, indexMinX, indexMinY); |
|
|
|
|
|
|
|
int[] indexes = new int[workCount]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(indexMinX != indexMinY) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
indexes[0] = indexMinY - 1; |
|
|
|
|
|
|
|
indexes[1] = indexMinX - 1; |
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) |
|
|
|
|
|
|
|
if (i != indexes[0] && i != indexes[1]) indexes[2] = i; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//WriteLine("index[2]= {0}", indexes[2]); |
|
|
|
|
|
|
|
//WriteLine(indexMinX + " " + indexMinY); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Points.Add(Gaussian(ref matrix, indexes[0] , indexes[1])); |
|
|
|
|
|
|
|
WriteLine("[{0:00.00} ;{1:00.00}] Линии: {2}", Points[Points.Count - 1].X, Points[Points.Count - 1].Y, Points[Points.Count - 1].Line); |
|
|
|
|
|
|
|
WriteLine(Points.Count + "\n\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Points.Add(Gaussian(ref matrix, indexes[0], indexes[2])); |
|
|
|
|
|
|
|
WriteLine("[{0:00.00} ;{1:00.00}] Линии: {2}", Points[Points.Count - 1].X, Points[Points.Count - 1].Y, Points[Points.Count - 1].Line); |
|
|
|
|
|
|
|
WriteLine(Points.Count + "\n\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (Point p in Points) WriteLine("{0:0.0} {1:0.0} {2}", p.X, p.Y, p.Line); |
|
|
|
|
|
|
|
WriteLine("\n\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug.Add(new Point |
|
|
|
if (Points[Points.Count - 1].X < 0 || Points[Points.Count - 1].Y < 0) Points.RemoveAt(Points.Count - 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Points[Points.Count - 2].X > Points[Points.Count - 1].X) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
Points.RemoveAt(Points.Count - 1); |
|
|
|
Y = matrix[i, 2] / matrix[i, 1], |
|
|
|
Points.Add(Gaussian(ref matrix, indexes[1], indexes[2])); |
|
|
|
X = 0, |
|
|
|
} |
|
|
|
Line = i + 1 |
|
|
|
else { |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
double tempQ = 0D; |
|
|
|
|
|
|
|
for (int i= 1; i < 4; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
WriteLine("{0} {1:0.0} {2:0.0}", i, Points[Points.Count - i].X, Points[Points.Count - i].Y); |
|
|
|
|
|
|
|
double t = Result(matrix, Points[Points.Count - i].X, Points[Points.Count - i].Y); |
|
|
|
|
|
|
|
if (tempQ < t) tempQ = t; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WriteLine("{0:0.0}", tempQ); |
|
|
|
debug.Add(new Point |
|
|
|
} |
|
|
|
{ |
|
|
|
|
|
|
|
Y = 0, |
|
|
|
|
|
|
|
X = matrix[i, 2] / matrix[i, 0], |
|
|
|
|
|
|
|
Line = i + 1 |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Points.Add(new Point |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Y = yMin, |
|
|
|
|
|
|
|
X = 0, |
|
|
|
|
|
|
|
Line = indexMinY |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Points.Add(new Point |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Y = 0, |
|
|
|
|
|
|
|
X = xMin, |
|
|
|
|
|
|
|
Line = indexMinX |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (Point p in debug) WriteLine("X: {0,-7:0.0} Y: {1,-7:0.0} Line: {2}", p.X, p.Y, p.Line); |
|
|
|
|
|
|
|
Write("\n"); //debug показывает все точки пересечения с осями чтоб можно было нарисовать |
|
|
|
|
|
|
|
if (indexMinX == indexMinY) goto Result; //если индексы минимальных точек одинаковы, то сразу к вычислениям |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int[] indexes = new int[workCount]; //нахождение линии, которая не имеет минимальных точек на осях |
|
|
|
|
|
|
|
indexes[0] = indexMinY - 1; |
|
|
|
|
|
|
|
indexes[1] = indexMinX - 1; |
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) |
|
|
|
|
|
|
|
if (i != indexes[0] && i != indexes[1]) indexes[2] = i; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Points.Add(Gaussian(matrix, indexes[0], indexes[1])); //нажоджение точки пересечения основной линии (у которой minY) и второй линии (у которой minX) |
|
|
|
|
|
|
|
WriteLine("X: {0,-7:0.0} Y: {1,-7:0.0} Line: {2}", Points[Points.Count - 1].X, Points[Points.Count - 1].Y, Points[Points.Count - 1].Line); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Points.Add(Gaussian(matrix, indexes[0], indexes[2])); //нахождение точки пересечения основной линиии и третьей |
|
|
|
|
|
|
|
WriteLine("X: {0,-7:0.0} Y: {1,-7:0.0} Line: {2}", Points[Points.Count - 1].X, Points[Points.Count - 1].Y, Points[Points.Count - 1].Line); |
|
|
|
|
|
|
|
//if (Points[Points.Count - 1].X < 0 || Points[Points.Count - 1].Y < 0) Points.RemoveAt(Points.Count - 1); |
|
|
|
|
|
|
|
WriteLine(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (Point p in Points) WriteLine("X: {0,-7:0.0} Y: {1,-7:0.0} Line: {2}", p.X, p.Y, p.Line); |
|
|
|
|
|
|
|
WriteLine("\n\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Points[Points.Count - 2].X < Points[Points.Count - 1].X || Points[Points.Count - 1].X == 0) |
|
|
|
|
|
|
|
{ //если Х первой точки пересечения меньше, то вторая точка отсекается |
|
|
|
|
|
|
|
Points.RemoveAt(Points.Count - 1); //с 0 - частный случай |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else //иначе отсекается первая точка и добавляется точка пересечения второй и третьей линий |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
Points.RemoveAt(Points.Count - 2); |
|
|
|
|
|
|
|
Points.Add(Gaussian(matrix, indexes[1], indexes[2])); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Result: |
|
|
|
|
|
|
|
foreach (Point p in Points) WriteLine("X: {0,-7:0.0} Y: {1,-7:0.0} Line: {2}", p.X, p.Y, p.Line); |
|
|
|
|
|
|
|
WriteLine("\n\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double[] results = new double[Points.Count]; |
|
|
|
|
|
|
|
double result = 0D; |
|
|
|
|
|
|
|
int indRes = 0; |
|
|
|
|
|
|
|
for (int i = 0; i < results.Length; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
results[i] = Result(matrix, Points[Points.Count - (i + 1)].X, Points[Points.Count - (i + 1)].Y); |
|
|
|
|
|
|
|
if (results[i] > result) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
result = results[i]; |
|
|
|
|
|
|
|
indRes = results.Length - 1 - i; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
WriteLine("{0} [{1:0.0} {2:0.0}] {4} \t\t Сумма: {3:0.0}\n", |
|
|
|
|
|
|
|
i, Points[Points.Count - (i + 1)].X, Points[Points.Count - (i + 1)].Y, results[i], Points[Points.Count - (i + 1)].Line); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
WriteLine("\n\nДеталей первого типа: {1}, второго : {2} \nС максимальной прибылью в {3:0.0} ({0})", |
|
|
|
|
|
|
|
Points[indRes].Line, (int)Points[indRes].X, (int)Points[indRes].Y, result); |
|
|
|
ReadKey(); |
|
|
|
ReadKey(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -149,8 +160,8 @@ namespace linear |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// метод гауса для нахождения координаты пересечения |
|
|
|
// метод гаусcа для нахождения координаты пересечения |
|
|
|
public static Point Gaussian(ref double[,] matrix, int line1, int line2) |
|
|
|
public static Point Gaussian(double[,] matrix, int line1, int line2) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Point p = new Point(); |
|
|
|
Point p = new Point(); |
|
|
|
double kof; |
|
|
|
double kof; |
|
|
@ -162,7 +173,7 @@ namespace linear |
|
|
|
tempY = matrix[line1, 1] - matrix[line2, 1] * kof; |
|
|
|
tempY = matrix[line1, 1] - matrix[line2, 1] * kof; |
|
|
|
tempRes = matrix[line1, 2] - matrix[line2, 2] * kof; |
|
|
|
tempRes = matrix[line1, 2] - matrix[line2, 2] * kof; |
|
|
|
|
|
|
|
|
|
|
|
WriteLine("{0:00.00} : [{1:00.00};{2:00.00}] = {3:00.00}", kof, tempX, tempY, tempRes); |
|
|
|
//WriteLine("{0:00.00} : [{1:00.00};{2:00.00}] = {3:00.00}", kof, tempX, tempY, tempRes); |
|
|
|
if ((int)tempX != 0) throw new FormatException(); |
|
|
|
if ((int)tempX != 0) throw new FormatException(); |
|
|
|
p.Y = tempRes / tempY; |
|
|
|
p.Y = tempRes / tempY; |
|
|
|
p.X = (matrix[line2, 2] - matrix[line2, 1] * p.Y) / matrix[line2, 0]; |
|
|
|
p.X = (matrix[line2, 2] - matrix[line2, 1] * p.Y) / matrix[line2, 0]; |
|
|
|