Skip to content

Instantly share code, notes, and snippets.

@Eleobert
Created October 25, 2020 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eleobert/69cedf71868a915b8ec7561a8476e384 to your computer and use it in GitHub Desktop.
Save Eleobert/69cedf71868a915b8ec7561a8476e384 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<center>\n",
"РОССИЙСКИЙ УНИВЕРСИТЕТ ДРУЖБЫ НАРОДОВ\n",
" \n",
" Факультет физико-математических и естественных наук\n",
"\n",
"## Кафедра прикладной информатики и теории вероятносте\n",
"</center>\n",
"\n",
"## Практическая работа № 2\n",
"«Анализ систем массового обслуживания»\n",
"По дисциплинам:\n",
"\n",
"«Основы математической теории телетрафика» <div style=\"text-align: right\"> Учебная группа НКИ-3 </div>\t\t\t\t\t\n",
"Баллы: 15 баллов"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Задача 1** (6 баллов). Для второй модели Эрланга (СМО M/M/v/r) с интенсивностью входящего потока $\\mu$ и интенсивностью обслуживания $\\lambda$\n",
"\n",
"1. Найти v по заданному среднему времени $v$ пребывания в системе принятого в систему требования.\n",
"\n",
"$\\lambda$=4 $\\;$ $\\mu$=1 $\\;$ r=3 $\\;$ v=1.063352"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"r = 3\n",
"l = 4\n",
"mu = 1\n",
"v = 1.063352\n",
"rho = l / mu \n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Стационарная вероятность того, что в системе находится 0 заявок c $x$ мест ожидания.:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def p0(x):\n",
" a = rho**x / fact(x)\n",
" b = (rho/x)**(r+1) - 1 \n",
" c = rho / x - 1\n",
" return 1 / (sum([rho**i / fact(i) for i in range(x)]) + a * b / c)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Факториал n:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def fact(n):\n",
" r = 1\n",
" for i in range(1, n+1): \n",
" r = r * i\n",
" return r"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Стационарная вероятность того, что в системе находится $i$ заявок c $x$ мест ожидания."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def p(i, x):\n",
" if i < x:\n",
" return rho**i / fact(i) * p0(x)\n",
" return rho**i / (x**(i - x) * fact(x)) * p0(x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Cтационарное среднее время ожидания начала обслуживания, где\n",
"x - число мест ожидания."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def w(x):\n",
" a = p(x, x) / (1 - p(x + r, x))\n",
" b = x*mu - (rho/x)**r * (x*mu*(r + 1) - r*l)\n",
" c = (l - x*mu)**2\n",
" return a * b / c"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Стационарное среднее время пребывания в системе, где\n",
"x - число мест ожидания."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"def f(x):\n",
" return w(x) + 1 / mu"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ответ: 6\n"
]
}
],
"source": [
"def norm(x):\n",
" return abs(f(x) - v)\n",
"\n",
"res = [norm(x) if x != 4 else float(\"nan\") for x in range(1, 50)]\n",
"val, idx = min((val, idx) for (idx, val) in enumerate(res))\n",
"t = idx + 1\n",
"print(\"Ответ:\", t)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.0633520809898762"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f(t)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2. Вычислить следующие стационарные характеристики обслуживания (4 балла):"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"а) вероятность потери $\\pi$. "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ответ: 0.029800794493837587\n"
]
}
],
"source": [
"print(\"Ответ:\", p(t + r, t))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"б) вероятность немедленного обслуживания $\\beta$ ;"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.7578685447375698\n"
]
}
],
"source": [
"print(sum([p(i, t) for i in range(0, t)]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"в) математическое ожидание и дисперсию длины очереди;"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"математическое ожидание длины очереди: 0.2458565545741601\n",
"дисперсия длины очереди : 0.4536182595916215\n"
]
}
],
"source": [
"expected = sum([(i - t) * p(i, t) for i in range(t, t + r + 1)])\n",
"print(\"математическое ожидание длины очереди:\", expected)\n",
"\n",
"expected_2 = sum([(i - t)**2 * p(i, t) for i in range(t, t + r + 1)])\n",
"variance = expected_2 - expected**2\n",
"print(\"дисперсия длины очереди :\", variance)\n",
" "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment