Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('BR', '<br/>'); #Html :)
- define('ACTIVAR_LOG', 0); #Mostrar mas mensajes
- define('HV', 999999); #High Value
- define('DURACION', 90000);
- define('CANTIDAD_DE_EXTRACCIONISTAS_ADULTOS', 1);
- define('CANTIDAD_DE_EXTRACCIONISTAS_DELICADOS', 1);
- define('IA_MIN',5); #MÃnimo intervalo entre arribos, fdp lineal
- define('IA_MAX',15); #Máximo intervalo entre arribos, fdp lineal
- define('TAA_MIN', 5); #MÃnimo tiempo de atención, fdp lineal
- define('TAA_MAX',15); #Máximo tiempo de atención, fdp lineal
- define('TAD_MIN', 5); #MÃnimo tiempo de atención, fdp lineal
- define('TAD_MAX',15); #Máximo tiempo de atención, fdp lineal
- $simulador = new simulador(CANTIDAD_DE_EXTRACCIONISTAS_ADULTOS, CANTIDAD_DE_EXTRACCIONISTAS_DELICADOS,DURACION);
- $simulador->ejecutar();
- class simulador {
- private $T=0; #Tiempo actual
- private $X=null; #Cantidad de puestos
- private $Y=null; #Cantidad de puestos
- private $tiempo_final=null; #Duración de la simulación
- private $TPSA = array();
- private $TPSD = array();
- private $TPLL = 0;
- private $NSD = 0;
- private $TD = 0;
- private $STOD = array();
- private $STSD = 0;
- private $STLLD = 0;
- private $NSA = 0;
- private $TA = 0;
- private $STOA = array();
- private $ITOD = array();
- private $ITOA = array();
- private $STAD = 0;
- private $STAA = 0;
- private $STSA = 0;
- private $STLLA = 0;
- /**
- * @param integer $this->tiempo_final Tiempo de ejecución
- * @return void
- */
- public function __construct($X, $Y,$tiempo_final){
- $this->X = $X;
- $this->Y = $Y;
- $this->tiempo_final = $tiempo_final;
- return $this;
- }
- public function ejecutar(){
- $this->inicio = microtime(true);
- $this->inicializar();
- do
- {
- $menor_tpsa_key = $this->min_key($this->TPSA);
- $menor_tpsd_key = $this->min_key($this->TPSD);
- $menor_tpsa = $this->TPSA[$menor_tpsa_key];
- $menor_tpsd = $this->TPSD[$menor_tpsd_key];
- /*echo "<br>TPLL: " . $this->TPLL;
- echo "Listas de TPSA: " .BR;
- print_r($this->TPSA);
- echo BR."Menor tpsa key: " .$menor_tpsa_key." => Menor tpsa: " . $menor_tpsa . "<br>".BR.BR;
- echo "Listas de TPSD: " .BR;
- print_r($this->TPSD);
- echo BR."Menor tpsd key: " .$menor_tpsd_key." => Menor tpsd: " . $menor_tpsd . "<br>".BR.BR.BR.BR.BR.BR;*/
- if ($this->TPLL <= $menor_tpsa )
- {
- if ($this->TPLL <= $menor_tpsd) # LLEGADA
- {
- $this->T = $this->TPLL;
- $IA = $this->generar_intervalo_entre_arribos();
- $this->TPLL = $this->T + $IA;
- $tipo_paciente = $this->generar_tipo_paciente();
- if ($tipo_paciente == "DELICADO") # PACIENTES DELICADOS
- {
- $this->NSD++;
- $this->TD++;
- $this->STLLD = $this->STLLD + $this->T;
- $cola_hv_key = $this->buscar_cola_hv($this->TPSD);
- if ($this->NSD <= $this->Y) {
- $TAD = $this->generar_tiempo_de_atencion_delicado();
- $this->TPSD[$cola_hv_key] = $this->T + $TAD;
- $this->STOD[$cola_hv_key] = $this->STOD[$cola_hv_key] + ($this->T - $this->ITOD[$cola_hv_key]);
- $this->STAD = $this->STAD + $TAD;
- }
- }
- else # PACIENTES ADULTOS
- {
- $this->NSA++;
- $this->TA++;
- $this->STLLA = $this->STLLA + $this->T;
- $cola_hv_key = $this->buscar_cola_hv($this->TPSA);
- if ($this->NSA <= $this->X) {
- $TAA = $this->generar_tiempo_de_atencion_adulto();
- /*echo "HAY UNA LLEGADA".BR.BR;
- echo "TIEMPO DE ATENCION DE ADULTOS: ". $TAA.BR;
- echo "CANTIDAD DE ADULTOS: " . $this->TA.BR.BR;*/
- $this->TPSA[$cola_hv_key] = $this->T + $TAA;
- $this->STOA[$cola_hv_key] = $this->STOA[$cola_hv_key] + ($this->T - $this->ITOA[$cola_hv_key]);
- $this->STAA = $this->STAA + $TAA;
- }
- }
- } else { # SALIDA DELICADOS
- $this->procesarSalida(null, $menor_tpsd_key);
- }
- }
- else # SALIDA ADULTOS
- {
- $this->procesarSalida($menor_tpsa_key, $menor_tpsd_key);
- }
- //$this->NT++;
- } while($this->T <= $this->tiempo_final);
- $this->vaciamiento();
- $this->imprimir();
- }
- private function procesarSalida($menor_tpsa_key=null, $menor_tpsd_key=null) {
- if (!$menor_tpsa_key && !$menor_tpsd_key) # VACIAMIENTO
- {
- $menor_tpsa_key = $this->min_key($this->TPSA);
- $menor_tpsd_key = $this->min_key($this->TPSD);
- $menor_tpsa = $this->TPSA[$menor_tpsa_key];
- $menor_tpsd = $this->TPSD[$menor_tpsd_key];
- if ($menor_tpsd <= $menor_tpsa) { # SALE UN DELICADO
- $this->procesarSalidaDelicado($menor_tpsd_key);
- } else { # SALE UN ADULTO
- $this->procesarSalidaAdulto($menor_tpsa_key);
- }
- }
- else if($menor_tpsa_key == null && $menor_tpsd_key != null) # SACO SOLO DELICADOS
- {
- $this->procesarSalidaDelicado($menor_tpsd_key);
- }
- else #HAY QUE VER SI SACO ADULTOS O DELICADOS
- {
- $menor_tpsa = $this->TPSA[$menor_tpsa_key];
- $menor_tpsd = $this->TPSD[$menor_tpsd_key];
- if ($menor_tpsd <= $menor_tpsa)
- {
- $this->procesarSalidaDelicado($menor_tpsd_key);
- } else {
- $this->procesarSalidaAdulto($menor_tpsa_key);
- }
- }
- }
- private function procesarSalidaDelicado($menor_tpsd_key) {
- $this->T = $this->TPSD[$menor_tpsd_key];
- $this->STSD = $this->STSD + $this->TPSD[$menor_tpsd_key];
- $this->NSD--;
- if ($this->NSD >= $this->Y)
- {
- $TAD = $this->generar_tiempo_de_atencion_delicado();
- $this->TPSD[$menor_tpsd_key] = $this->T + $TAD;
- $this->STAD = $this->STAD + $TAD;
- }
- else
- {
- $this->ITOD[$menor_tpsd_key] = $this->T;
- $this->TPSD[$menor_tpsd_key] = HV;
- }
- }
- private function procesarSalidaAdulto($menor_tpsa_key) {
- $this->T = $this->TPSA[$menor_tpsa_key];
- $this->STSA = $this->STSA + $this->TPSA[$menor_tpsa_key];
- $this->NSA--;
- if ($this->NSA >= $this->X)
- {
- $TAA = $this->generar_tiempo_de_atencion_adulto();
- /*echo "HAY UNA SALIDA".BR.BR;
- echo "TIEMPO DE ATENCION DE ADULTOS: ". $TAA.BR;
- echo "CANTIDAD DE ADULTOS: " . $this->TA.BR.BR;*/
- $this->TPSA[$menor_tpsa_key] = $this->T + $TAA;
- $this->STAA = $this->STAA + $TAA;
- }
- else
- {
- $this->ITOA[$menor_tpsa_key] = $this->T;
- $this->TPSA[$menor_tpsa_key] = HV;
- }
- }
- private function generar_tipo_paciente() {
- $r = mt_rand (0*10, 1*10) / 10;
- if ($r <= 0.15)
- return "DELICADO";
- else
- return "ADULTO";
- }
- private function buscar_cola_hv($cola) {
- foreach ($cola as $key => $puesto) {
- if ($puesto == HV) {
- return $key;
- }
- }
- return false;
- }
- private function generar_tiempo_de_atencion_delicado() {
- #fdp lineal
- return rand(TAD_MIN,TAD_MAX);
- }
- private function generar_tiempo_de_atencion_adulto() {
- #fdp lineal
- return rand(TAA_MIN,TAA_MAX);
- }
- private function inicializar(){
- for ($i=1; $i <= $this->X; $i++) {
- $this->TPSA[$i] = HV;
- $this->STOA[$i] = 0;
- $this->ITOA[$i] = 0;
- }
- for ($j=1; $j <= $this->Y; $j++) {
- $this->TPSD[$j] = HV;
- $this->STOD[$j] = 0;
- $this->ITOD[$j] = 0;
- }
- }
- private function min_key($array){
- $min = HV;
- $key_num = 0;
- foreach ($array as $key => $value) {
- if($array[$key] <= $min) {
- $min = $array[$key];
- $key_num = $key;
- }
- }
- return $key_num;
- }
- private function generar_intervalo_entre_arribos(){
- #fdp lineal
- return rand(IA_MIN,IA_MAX);
- }
- private function vaciamiento(){
- $total_restantes = $this->NSA + $this->NSD;
- if ($total_restantes != 0) {
- $this->TPLL = HV;
- for ($i = 1; $i <= $total_restantes; $i++) {
- $this->procesarSalida();
- }
- }
- }
- private function imprimir(){
- echo 'Duracion de la simulación (CPU): '.(string)(microtime(true)-$this->inicio).BR;
- echo 'Variable Exógena de Control->Cantidad de Extraccionistas Adultos X: '.$this->X.BR;
- echo 'Variable Exógena de Control->Cantidad de Extraccionistas Delicados Y: '.$this->Y.BR;
- echo 'Variable Exógena de Control->Duracion de la simulacion: '.$this->tiempo_final.BR.BR;
- echo 'Cantidad de adultos atendidos: ' . $this->TA.BR;
- echo 'Sumatoria de tiempos de llegada adultos: '.number_format($this->STLLA,2).BR;
- echo 'Sumatoria de tiempos de salida adultos: '.number_format($this->STSA,2).BR;
- echo 'Sumatoria de tiempos de atencion adultos: '.number_format($this->STAA,2).BR.BR;
- echo 'Cantidad de delicados atendidos: ' . $this->TD.BR;
- echo 'Sumatoria de tiempos de llegada delicados: '.number_format($this->STLLD,2).BR;
- echo 'Sumatoria de tiempos de salida delicados: '.number_format($this->STSD,2).BR;
- echo 'Sumatoria de tiempos de atencion delicados: '.number_format($this->STAD,2).BR.BR;
- $PECA = ($this->STSA - $this->STLLA - $this->STAA) / $this->TA;
- $PECD = ($this->STSD - $this->STLLD - $this->STAD) / $this->TD;
- echo 'Promedio de espera en cola de adultos: '.$PECA.BR ;
- echo 'Promedio de espera en cola de delicados: '.$PECD.BR;
- for ($i = 1; $i <= $this->X; $i++) {
- echo 'Promedio tiempo oscioso del extraccionista de adultos: <b>' . $i . '</b>: ' . ($this->STOA[$i]*100) / $this->T.BR;
- }
- for ($j = 1; $j <= $this->Y; $j++) {
- echo 'Promedio tiempo oscioso del extraccionista de delicados <b>' . $j . '</b>: ' . ($this->STOD[$j]*100) / $this->T.BR;
- }
- echo BR;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement