function [output] = run_pr
 
	global i_dev_ed
	global i_art_ed
	global i_apt_ed
	global i_rt_edt
	global i_pt_edt 
	global i_qua_ed 
	global i_us_co i_av_ld i_av_wt i_av_lr i_av_sr
	global hResult hStop hStart hPauseon
	global b_pause
	
	b_pause = 0;
	
	% кол-во устройств
	devices = str2num(get(i_dev_ed,'String'));
	
	% среднее время поступления заявки
	avg_request_time = str2num(get(i_art_ed,'String'));
	
	% среднее время обработки заявки
	avg_processing_time = str2num(get(i_apt_ed,'String'));
	
	%Генераторы
	e_request = str2num(get(i_rt_edt,'String'));
	e_processing = str2num(get(i_pt_edt,'String'));
	
	%Квант времени
	quant = str2num(get(i_qua_ed,'String'));
	
	if gcbo==hStart
		set(hStart,'Enable','off');
   
		set(i_dev_ed,'Enable','off');
		set(i_art_ed,'Enable','off');
		set(i_apt_ed,'Enable','off');
		set(i_rt_edt,'Enable','off');
		set(i_pt_edt,'Enable','off');
		set(i_qua_ed,'Enable','off');
   
		set(hPauseon,'Enable','on');
   
	end;
	
	% количество измерений
	n = 1000;
	
	counter = 0;
		
	% начальное время поступления заявки
	request_time = rp_gen(e_request, avg_request_time);
	
	for i=1:1:devices
		device(i) = 0;
		device_processig_request(i) = 0;
		device_processing_time(i) = 0;
		device_bwt(i) = 0;
		device_twt(i) = 0;
	end;
	
	for i=1:1:n
		request_processing_time(i) = 0;
		
		array_system_rn(i) = 0;
		array_line_rn(i) = 0;
		array_time(i) = 0;
	end;
	
	line = 0;
	
	line_trn = 0;
	
	delay = 0;
	
	time = 0;
	
	k = 1;
	
	pt_sum = 0;
	
	while k ~= n	
	
	% ОПРЕДЕЛЕНИЕ СВОБОДНЫХ УСТРОЙСТВ И ПОМЕЩЕНИЕ ЗАЯВКИ НА ОБРАБОТКУ
	flag = 0;
	for i=1:1:devices
		if (device(i) == 0) 
			if ((line == 0) && (request_time == time) && flag == 0)
				device(i) = 1;
				device_bwt(i) = time;
				
				e_processing = initial_v_gen(e_processing);
				new_processing_time = rp_gen(e_processing, avg_processing_time);
				
				pt_sum = pt_sum + new_processing_time;
							
				request_processing_time(k) = new_processing_time;
				device_processig_request(i) = k;
							
				if (new_processing_time <= quant)
					device_processing_time(i) = time + new_processing_time;
				else
					device_processing_time(i) = time + quant;
				end;
				
				device_twt(i) = device_twt(i) + device_processing_time(i) - time;
				
				flag = 1;
			end;
		end;
	end;
	for i=1:1:devices
		if (device(i) == 0)
			if (line ~= 0)
				device(i) = 1;
				device_bwt(i) = time;
				
				new_processing_time = line_rpt(1);
				device_processig_request(i) = line_rn(1);
				request_processing_time(line_rn(1)) = line_rpt(1);
				
				if (new_processing_time <= quant)
					device_processing_time(i) = time + new_processing_time;
				else
					device_processing_time(i) = time + quant;
				end;
				
				device_twt(i) = device_twt(i) + device_processing_time(i) - time;
				
				line_trn = line_trn + 1;
				line_tlt(line_trn) = time - line_rjt(1);
				
				for j=1:1:line-1
					line_rn(j) = line_rn(j + 1);
					line_rjt(j) = line_rjt(j + 1);
					line_rpt(j) = line_rpt(j + 1);
				end;
				
				line_rn(line) = 0;
				line_rjt(line) = 0;
				line_rpt(line) = 0;
				line = line - 1;
			end;
		end;
	end;
	
	% ВЫЧИСЛЕНИЕ ВРЕМЕНИ ПОСТУПЛЕНИЯ ЗАЯВКИ
	if (request_time == time)
        k = k + 1;
      	e_request = initial_v_gen(e_request);
		new_request_time = rp_gen(e_request, avg_request_time);
		request_time = request_time + new_request_time;
	end;
	
	% ВЫЧИСЛЕНИЕ МИНИМАЛЬНОГО ВРЕМЕНИ ОБРАБОТКИ  "time_tick"
	time_tick = 0;
	tmp = 0;

	
	tmp = max(device_processing_time);
	for i=1:1:devices
		if ((device_processing_time(i) < tmp) && (device_processing_time(i) ~= 0))
			tmp = device_processing_time(i);
		end;
	end;
	time_tick = tmp;
	
	if (time_tick > time + quant)
		time_tick = time + quant;
	end;
		
	% ВЫЧИСЛЕНИЕ ВРЕМЕНИ ЗАДЕРЖКИ "delay"
	if ((request_time < time_tick) && (time_tick ~= 0))
		delay = (request_time - time) * line + delay;
	else
		if ((request_time > time_tick) && (time_tick ~= 0))
			delay = (time_tick - time) * line + delay;
		end;
	end;
	
	% ВЫЧИСЛЕНИЕ СИСТЕМНОГО ВРЕМЕНИ "time"
	flag  = 0;
	for i=1:1:devices
		if (device_processing_time(i) ~= 0)
			flag = flag + 1;
		end;
	end;
    
	if ((flag == devices) || ((flag ~= devices) && (line == 0)))
		time = time_tick;
	end;
	if ((flag ~= devices) && (line ~= 0))
		time = time;
	end;
	if (((flag == 0) && (line == 0)) || (request_time <= time_tick))
		time = request_time;
	end;
	
	
	% ФОРМИРОВАНИЕ ОЧЕРЕДИ "line"
	flag = 0;
	
	for i=1:1:devices
		if (device(i) ~= 0)
			flag = flag + 1;
		end;
	end;
	
	if ((flag == devices) && (request_time == time)) 
		e_processing = initial_v_gen(e_processing);
		
		new_processing_time = rp_gen(e_processing, avg_processing_time);
		
		pt_sum = pt_sum + new_processing_time;
		
		line = line + 1;
		line_rn(line) = k;
		line_rjt(line) = time;
		line_rpt(line) = new_processing_time;
	end;
	
	% СНЯТИЕ ЗАЯВКИ С ОБРАБОТКИ И РЕАЛИЗАЦИЯ ЦИКЛИЧЕСКОЙ ОБРАБОТКИ
	for i=1:1:devices
		if (device(i) == 1)
			if (device_processing_time(i) == time) 
				request_processing_time(device_processig_request(i)) = request_processing_time(device_processig_request(i)) - quant;
				if (request_processing_time(device_processig_request(i)) <= quant)
					time = time + request_processing_time(device_processig_request(i));
					device(i) = 0;
					device_processig_request(i) = 0;
					device_processing_time(i) = 0;
					device_bwt(i) = 0;
				else
					line = line + 1;
					line_rn(line) = device_processig_request(i);
					line_rjt(line) = time;
					line_rpt(line) = request_processing_time(device_processig_request(i));
					
					device(i) = 0;
					device_processig_request(i) = 0;
					device_processing_time(i) = 0;
					device_bwt(i) = 0;
				end;
			end;
		end;
	end;
	
	
	
	% ВЫВОД ДАННЫХ В ИНТЕРФЕЙС И В КОНСОЛЬ
	
	% среднее число требований в очереди
	M = delay / time;
	M_array(k) = M; 
	fprintf('\nсреднее число требований в очереди = %f\n', M);
	
	%коэффициент использования системы
	csu = 0;
	for i=1:1:devices
		csu = csu + device_twt(i);
	end;
	csu = csu / (devices * time);
	fprintf('коэффициент использования системы = %f\n', csu);
	array_csu(k) = csu;
	
	% время в очереди
	ld = 0; 
	for i=1:1:line_trn
		ld = ld + line_tlt(i);
	end;	
	
	% средняя задержка в очереди
	av_ld = 0;
	if (line_trn ~= 0)
		av_ld = ld / line_trn;
	end;
	av_ld_array(k) = av_ld;
	fprintf('средняя задержка в очереди = %f\n', av_ld);
	
	% среднее время ожидания
	av_wt = pt_sum; 
	for i=1:1:line_trn
		av_wt = av_wt + line_tlt(i);
	end;
	av_wt = av_wt/n;
	av_wt_array(k) = av_wt;
	fprintf('среднее время ожидания = %f\n', av_wt);
	
	L = (av_wt * n) / time;	   
	L_array(k) = L;
	
	% Число требований в системе
	array_system_rn(k) = 0;
	for i=1:1:devices
		if (device(i) == 1)
			array_system_rn(k) = array_system_rn(k) + 1;
		end;
	end;
	array_system_rn(k) = array_system_rn(k) + line;
	
	% Число требований в очереди
	array_line_rn(k) = line;
	
	% Время
	array_time(k) = time; 
	
	set(i_us_co,'String',csu);
	set(i_av_ld,'String',av_ld);
	set(i_av_wt,'String',av_wt);
	set(i_av_lr,'String',M);
	set(i_av_sr,'String',L);
	
	axis('off');
	pause(0.2)
	while b_pause
		pause(1);
	end;

	cla;
	sw = -0.15;
	
	% УСТРОЙСТВА
	axis('off');
	subplot(1,1,1);
	axes('Position',[0 0.2 0.5 0.1],'XLim',[0 0.9],'YLim',[0 0.25],'Visible','off')
	for ji=1:1:devices
		if (device(ji) == 1)
			sw = sw + 0.15;
			rectangle('Position',[sw 0.1 0.13 0.13],'Curvature',[0,0],'FaceColor','r')
		else
			if (device(ji) == 0)
				sw = sw + 0.15;
				rectangle('Position',[sw 0.1 0.13 0.13],'Curvature',[0,0],'FaceColor','b')
			end;
		end;
	end;
 
	% ОЧЕРЕДЬ
	a = 0;
	if (line ~= 0)
		axes('Position',[0 0 0.5 0.2],'XLim',[0.02 0.6],'YLim',[0.05 0.2],'Visible','off') 
		for qw=1:1:line
			a = a + 0.03;
			rectangle('Position',[a 0.1 0.03 0.03],'Curvature',[1,1],'FaceColor','b')
		end;
	else 
		axes('Position',[0 0 0.5 0.2],'XLim',[0.02 0.6],'YLim',[0.05 0.2],'Visible','off') 
		if (line == 0)
			rectangle('Position',[0.03 0.1 0.03 0.03],'Curvature',[1,1])
		end;
	end; 
	
	end;
	
	results (array_system_rn, array_line_rn, array_csu, array_time, L_array, M_array, n);
	
	set(hStart,'Enable','on');
	
	set(i_dev_ed,'Enable','on');
	set(i_art_ed,'Enable','on');
	set(i_apt_ed,'Enable','on');
	set(i_rt_edt,'Enable','on');
	set(i_pt_edt,'Enable','on');
	set(i_qua_ed,'Enable','on');
	