Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Задание 5 - 8 отчеты.docx
Скачиваний:
2
Добавлен:
01.04.2025
Размер:
197.87 Кб
Скачать

Лабораторная работа № 7

Задание:

Исследовать модель мульти программной ЭВМ и вычислить:

  1. Вероятность занятости ЦП.

  2. Среднее число заданий обрабатывающихся и ожидающих обработки в ЦП.

  3. Стационарную вероятность распределения заданий по всем узлам вычислительной системы

  4. Стационарные вероятности скопления заданий на одном из периферийных устройств.

  5. Среднюю длительность ожидания завершения обработки задания в ЦП.

Вариант 17:

L = 6

N = 6

= 5/17 = 1/17 = 3/17 = 3/34 = 15/17 = 10/17

= 0.3 = 0.2 = 0.1 = 0.2 = 0.1 = 0.1

Код программы:

package ru;

Import org.Apache.Commons.Math3.Linear.*;

import java.text.DecimalFormat;

import java.util.*;

Import java.Util.List;

public class Main {

static int L = 6;

static int N = 6;

static double[][] O = {

{0.3, 0.2, 0.1, 0.2, 0.1, 0.1},

{1, 0, 0, 0, 0, 0},

{1, 0, 0, 0, 0, 0},

{1, 0, 0, 0, 0, 0},

{1, 0, 0, 0, 0, 0},

{1, 0, 0, 0, 0, 0},

};

static double[] m = {5.0 / 17, 1.0 / 17, 3.0 / 17, 3.0 / 34, 15.0 / 17, 10.0 / 17};

static double[] p = {0.3, 0.2, 0.1, 0.2, 0.1, 0.1};

static List<List<Integer>> all;

static List<Double> w;

static List<Double> x;

public static void main(String[] args) {

w = getW(O);

x = new ArrayList<Double>();

all = getAll(N);

for (int i = 0; i < w.size(); i++) {

x.add(w.get(i) / m[i]);

}

DecimalFormat formater = new DecimalFormat("###.########");

//first

List<List<Integer>> states1 = getStates1();

double p1 = P(states1);

System.out.println(formater.format(p1));

//second

List<List<List<Integer>>> states2 = getStates2();

double p2 = 0;

for (int i = 0; i < L; i++) {

p2 += (i + 1) * P(states2.get(i));

}

System.out.println(formater.format(p2));

//third

List<List<Integer>> states31 = getStates31();

double p31 = P(states31);

System.out.println(formater.format(p31));

List<List<Integer>> states32 = getStates32();

double p32 = P(states32);

System.out.println(formater.format(p32));

//fourth

System.out.println(formater.format(p2/m[0]));

}

private static List<List<Integer>> getStates32() {

List<List<Integer>> list = new ArrayList<List<Integer>>();

for (int i = 1; i < L; i++) {

List<Integer> temp = Arrays.asList(0, 0, 0, 0, 0, 0);

temp.set(i, N);

list.add(temp);

}

return list;

}

private static List<List<Integer>> getStates31() {

List<List<Integer>> list = new ArrayList<List<Integer>>();

list.add(Arrays.asList(1, 1, 1, 1, 1, 1));

return list;

}

private static List<List<List<Integer>>> getStates2() {

List<List<List<Integer>>> res = new ArrayList<List<List<Integer>>>();

for (int i = 0; i < L; i++) {

res.add(new ArrayList<List<Integer>>());

}

for (List<Integer> state : all) {

int id = state.get(0);

if (id > 0) {

res.get(id - 1).add(state);

}

}

return res;

}

private static List<List<Integer>> getStates1() {

List<List<Integer>> list = new ArrayList<List<Integer>>();

for (List<Integer> state : all) {

if (state.get(0) > 0) {

list.add(state);

}

}

return list;

}

private static double P(List<List<Integer>> states) {

return G(states) / G(all);

}

private static double G(List<List<Integer>> states) {

double res = 0;

for (List<Integer> state : states) {

double mul = 1.0;

for (int i = 1; i < state.size(); i++) {

mul *= Math.pow(p[i] / m[i], state.get(i));

}

mul *= 1.0 / Math.pow(m[0], state.get(0));

res += mul;

}

return res;

}

private static List<List<Integer>> getAll(int N) {

List<List<Integer>> list = new ArrayList<List<Integer>>();

int max = (int) Math.pow(10, N);

for (int i = 0; i < max; i++) {

List<Integer> temp = new ArrayList<Integer>();

int x = i;

for (int j = 0; j < N; j++) {

temp.add(x % 10);

x /= 10;

}

if (check(temp, N)) {

list.add(temp);

}

}

return list;

}

private static boolean check(List<Integer> list, int N) {

int sum = 0;

for (Integer x : list) {

sum += x;

if (x < 0 || x > N) {

return false;

}

}

return sum == N;

}

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);

}

}

Результат работы программы:

Вероятность занятости ЦП – 0,807

Среднее число заданий, ожидающих обработки и обрабатывающихся в ЦП - 2,373

Вероятность равномерного распределения заданий по узлам - 0,0000097

Вероятности скопления всех заданий на одном периферийном устройстве:

p2 = 0,0526093665067609

p3 = 0,0000011276013054

p4 = 0,0046186549470956

p5 = 0,0000000000721665

p6 = 0,0000000008220214

Вероятность скопления всех заданий на каком-либо периферийном устройстве 0,05722915

Среднее время ожидания обработки задания в ЦП – 8,06873547

Выводы:

Из полученных результатов можно увидеть, что ЦП практически всегда занят и среднее количество заданий в ЦП составляет 2-3 задания. Вероятность равномерного распределения заданий мала, это вызвано неравномерным распределением интенсивности обработки заданий в каждом устройстве. Вероятность того что все задания будут находиться в одном периферийном устройстве наиболее высока для устройств 2 и 4, так как вероятность поступления заданий в них наиболее высока среди всех периферийных устройств (0.2) и эти устройства наиболее медленно обрабатывают задания. Вероятность скопления всех заданий в одном устройстве наиболее низка в устройствах 5 и 6, так как они обладают самой высокой интенсивностью обработки заданий и самой низкой вероятностью поступления в них заданий. Среднее время ожидания обработки задания в ЦП составляет около 8 временных единиц.