Лабораторная работа № 6
Задание:
Определить вектор числа обслуживающих приборов в системах СеМО, при котором будет достигнуто наименьшее значение функции потерь.
Вариант 17:
L = 4
= 8.6 = 5.8 = 6.6 = 5.8
r/q = 2.6
Ɵ =
Код программы:
package ru;
import org.apache.commons.math3.linear.*;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static List<Double> solve(double[][] coef, double[] cons) {
RealMatrix matrix = new Array2DRowRealMatrix(coef);
DecompositionSolver solver = new LUDecomposition(matrix).getSolver();
RealVector constants = new ArrayRealVector(cons);
RealVector solution = solver.solve(constants);
List<Double> list = new ArrayList<Double>();
for (double num : solution.toArray()) {
list.add(num);
}
return list;
}
private static int factorial(int x) {
int result = 1;
for (int i = 1; i <= x; i++) {
result *= i;
}
return result;
}
public static List<Double> getW(double[][] O) {
double[][] coef = new double[O.length][];
double[] cons = new double[O.length];
coef[coef.length - 1] = new double[O.length];
for (int i = 0; i < coef.length - 1; i++) {
coef[i] = O[i];
coef[i][i] -= 1.0;
cons[i] = 0;
}
for (int i = 0; i < coef[coef.length - 1].length; i++) {
coef[coef.length - 1][i] = 1;
}
cons[O.length - 1] = 1;
return solve(coef, cons);
}
private static Parameters getParameters(int k, double lam, double mu) {
double psi = lam / (mu * k);
if (psi >= 1) {
throw new IllegalArgumentException("Is to big " + psi);
}
double h = psi * k;
double g = (1 - psi) * k;
double temp1 = Math.pow(k * psi, k) / ((1 - psi) * factorial(k));
double temp2 = 0;
for (int i = 0; i < k; i++) {
temp2 += Math.pow(k * psi, i) / factorial(i);
}
double p0 = 1 / (temp1 + temp2);
double b = p0 * Math.pow(k * psi, k) * psi / (factorial(k) * (1 - psi) * (1 - psi));
double n = b + h;
double u = n / lam;
double w = b / lam;
return new Parameters(p0, b, h, g, n, u, w);
}
public static void main(String[] args) {
int L = 4;
double lam0 = 25.2;
double[][] O = {
{0, 0.5, 0.1, 0, 0.4},
{0, 0, 0, 0.8, 0.2},
{1, 0, 0, 0, 0},
{0.7, 0.3, 0, 0, 0},
{0, 0, 0.7, 0.3, 0},
};
double[] m = {0, 8.6, 5.8, 6.6, 5.8};
double rq = 2.6;
List<Double> w = getW(O);
List<Double> lam = new ArrayList<Double>();
lam.add(lam0);
for (int i = 1; i <= L; i++) {
lam.add(lam0 * w.get(i) / w.get(0));
}
List<PsiStore> psiStores = new ArrayList<PsiStore>();
for (int i = 0; i < L; i++) {
psiStores.add(new PsiStore(lam.get(i + 1), m[i + 1]));
}
//start
int[] k = new int[L];
for (int i = 0; i < k.length; i++) {
k[i] = psiStores.get(i).getK();
double lastLw = getParameters(k[i], lam.get(i + 1), m[i + 1]).getW() * lam.get(i + 1);
double curLw = getParameters(k[i] + 1, lam.get(i + 1), m[i + 1]).getW() * lam.get(i + 1);
while (curLw - lastLw >= rq) {
k[i]++;
lastLw = getParameters(k[i], lam.get(i + 1), m[i + 1]).getW() * lam.get(i + 1);
curLw = getParameters(k[i] + 1, lam.get(i + 1), m[i + 1]).getW() * lam.get(i + 1);
}
}
double q = 1;
double r = q * rq;
XYSeries[] arrays = new XYSeries[4];
for (int i = 0; i < arrays.length; i++) {
arrays[i] = new XYSeries(i + 1);
for (int j = 0; j < 10; j++) {
int curK = k[i] + j;
double tmpW = getParameters(curK, lam.get(i + 1), m[i + 1]).getW();
arrays[i].add((double) curK, getRk(q, r, curK, lam.get(i + 1), tmpW));
}
}
JPanel content = new JPanel(new GridLayout(2, 4, 10, 10));
content.add(createGraphic("k", "R", arrays[0]));
content.add(createGraphic("k", "R", arrays[1]));
content.add(createGraphic("k", "R", arrays[2]));
content.add(createGraphic("k", "R", arrays[3]));
JFrame frame = new JFrame("Graphics");
frame.getContentPane().add(content);
frame.setSize(1000, 500);
frame.setLocation(20, 50);
frame.show();
}
private static ChartPanel createGraphic(String xName, String yName, XYSeries... values) {
XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
for (XYSeries value : values) {
xySeriesCollection.addSeries(value);
}
JFreeChart chart = ChartFactory.createXYLineChart("", xName, yName, xySeriesCollection, PlotOrientation.VERTICAL,
true, true, true);
return new ChartPanel(chart);
}
private static double getRk(double q, double r, int k, double lam, double w) {
return r * k + q * lam * w;
}
}
Результат работы программы:
Выводы: Таким образом, мы видим, что наименьшее значение функции потерь достигается при векторе обслуживающих приборов равном = 4, 6, 5, 6. При отклонении от этих значений, потери увеличатся либо из-за увеличения числа ненужных приборов, либо из-за увеличения числа требований в очереди.
