Documente Academic
Documente Profesional
Documente Cultură
Alumno:
Pacheco Torres, Moiss Yrwing
Aula: L-206
Ao Acadmico:
2014
Codigo Python:
# -*- coding: utf-8 -*from decimal import *
import datetime
import thread
import time
import math
from array import *
import random
global lnArrayColas
global promcaj
global tiempoTotal
class CCola01():
lnProLle = 2
lnAtenci = 2
llFree = True
lnTInici = 0
lnTFinal = 0
lnCola = 0
lnVenta = 20
lnVentas = 5
lnClientes = 0
lnProm = 0
lnTiempo = 1
lnRetirados = 0
# Simulacion
def omSimulacion(self):
self.lnTiempo = 1
#
self.lnTInici = time.clock()
self.lnTFinal = self.lnTInici + 60
#print self.lnTInici, self.lnTFinal
self.lnVentas = raw_input("Ingrese Numero de Ventanillas: ")
#for i in range(self.lnVenta):
#
self.lnArrayColas.append(0)
thread.start_new_thread(self.mxLlegadaClientes, ())
for i in range (0,self.lnVenta-1):
thread.start_new_thread(self.mxVentanillaClientes, (i,))
#thread.start_new_thread(self.mxSalidaClientes, ())
thread.start_new_thread(self.mxtiempo,())
# Llegada de clientes
def mxLlegadaClientes(self):
#while time.clock() <= self.lnTFinal:
while self.lnTiempo<480:
#Exponencial
r = random.random()
w=1-r
f=math.log(w)
x=-f/2
time.sleep(x)
#while not self.llFree:
#
continue
self.llFree = False
self.lnCola+=1
print 'Cola (In): ', self.lnCola
self.llFree = True
self.retiro()
# Ventanillas
def mxVentanillaClientes(self,num):
#while time.clock() <= self.lnTFinal:
while self.lnTiempo<480:
if self.lnCola == 0:
print 'Cola vacia ...'
time.sleep(0.5)
continue
while not self.llFree:
continue
self.llFree = False
cont=0
#for elemento in range(0,4):
# if lnArrayColas[elemento] == 0:
#
#
#
lnArrayColas[elemento] =1
cont = elemento
break
if lnArrayColas[num] == 1:
lnArrayColas[num] = 1
print 'Cola (Out): ', self.lnCola
print 'Ventanilla (Out): ', num
self.llFree = True
if self.lnCola != 0:
self.lnCola-= 1
self.lnClientes+=1
r = random.random()
s = random.random()
w= math.sqrt(-2*math.log(r))*math.cos(2*math.pi*s)
if r>=0.5:
z = 7 + 2.1 * w
else:
z = 7 - 2.1 * w
time.sleep(z)
self.lnProm+=z
self.llFree = False
lnArrayColas[num] =0
print 'Ventanilla (In): ', num
self.llFree = True
#retiro
def retiro(self):
r = random.random()*10
if self.lnCola == 6:
if r<=1:
self.lnCola-=1
print 'Cola (Out): ', self.lnCola
self.lnRetirados+=1
if self.lnCola == 7:
if r<=2:
self.lnCola-=1
print 'Cola (Out): ', self.lnCola
self.lnRetirados+=1
if self.lnCola == 8:
if r<=2:
self.lnCola-=1
print 'Cola (Out): ', self.lnCola
self.lnRetirados+=1
if self.lnCola == 9:
if r<=2:
self.lnCola-=1
print 'Cola (Out): ', self.lnCola
self.lnRetirados+=1
if self.lnCola == 10:
if r<=3:
self.lnCola-=1
print 'Cola (Out): ', self.lnCola
self.lnRetirados+=1
def mxtiempo(self):
self.lnTiempo=0
while self.lnTiempo<=480:
self.lnTiempo+=1
time.sleep(1)
z=self.lnProm/self.lnVenta
print 'Tiempo Promedio de Ventanillas: ', z
print 'Total de Clientes Atendidos: ', self.lnClientes
print 'Total de Clientes Retirados: ', self.lnRetirados
Capturas de Pantalla
2) Un sistema de inventarios.
Los parametros son los siguientes:
Cantidad pedida
Stock minimo
Ventas de acuerdo a distribucion normal con = 4 y = 1
Costo de pedido
Costo de oportunidad perdida
Costo almacenamiento
Distribucion de respuesta de proveedor
30% 1 dia
30% 2 dias
20% 3 dias
20% 4 dias.
Los resultados deben ser:
Costo Total
Ventas promedio por dia
Tiempo promedio de reposicion
Numero de ventas frustradas por falta de stock
Numero de pedidos realizados
Debe procesar 365 dias.
Codigo C++
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;
int tiempo = 365;
int ventas;
int cantidadapedir;
bool pedido = false;
int numeropedidos = 0;
int respuesta = 0;
double tiempoproreposicion = 0;
int cont1 = 0, cont2 = 0, cont3 = 0, cont4 = 0;
int funcionNormal(int media, int desviacion)
{
int diferencia = 10 - media;
int suma = 0;
for (int i = 0; i<13; i++)
suma += rand()%10 + 1;
suma/=11;
int valor = desviacion * (suma - diferencia) + media;
return valor;
}
void pedirproveedor()
{
bool flag = true;
int random;
pedido = true;
numeropedidos ++;
cout<<"El pedido de "<<cantidadapedir<<" articulos, esta siendo
procesado"<<endl;
if (respuesta == 1)
cout<<"El pedido sera entregado en "<<respuesta<<" dias"<<endl;
tiempoproreposicion += respuesta;
void main ()
{
int cantidad, stockminimo;
double costopedido, costoportunidad, costoalmacena;
cout<<"Cantidad de Articulos: ";
cin>>cantidad;
cantidadapedir = cantidad;
cout<<"Stock Minimo: ";
cin>>stockminimo;
cout<<"Costo por Pedido Realizado: ";
cin>>costopedido;
cout<<"Costo por Unidad Perdida: ";
cin>>costoportunidad;
cout<<"Costo por Almacenamiento: ";
cin>>costoalmacena;
double costototal = 0, ventaspro = 0, ventasfrustradas = 0;
int diferencia;
for (int dias = 0; dias<tiempo; dias++)
{
if (respuesta == 1)
{
cantidad += cantidadapedir;
respuesta = 0;
pedido = false;
}
cout<<"*******DIA"<<dias+1<<"********"<<endl;
cout<<"Se tienen "<<cantidad<<" articulos en el almacen."<<endl;
//principio o final?
costototal += cantidad*costoalmacena;
ventas = funcionNormal(4, 1);
//oportunidad perdida, se venden o todo se pierde si es menor?
if (cantidad-ventas < 0)
{
cout<<"Se vendieron "<<cantidad<<" articulos"<<endl;
ventaspro += ventas;
diferencia = ventas - cantidad;
cantidad = 0;
ventasfrustradas += diferencia;
costototal += diferencia * costoportunidad;
}
else
{
cantidad -= ventas;
cout<<"Se vendieron "<<ventas<<" articulos"<<endl;
ventaspro += ventas;
}
if (pedido == true)
respuesta--;
if (pedido == false && cantidad < stockminimo)
{
pedirproveedor();
costototal += costopedido;
}
}
cout<<"Costo Total: "<<costototal<<endl;
ventaspro /= tiempo;
cout<<"Ventas en Promedio: "<<ventaspro<<endl;
tiempoproreposicion /= numeropedidos;
cout<<"Tiempo Promedio de Reposicion "<<tiempoproreposicion<<endl;
cout<<"Ventas Frustradas: "<<ventasfrustradas<<endl;
cout<<"Pedidos Realizados: "<<numeropedidos<<endl;
system ("pause");
}
Capturas de Pantalla
Cantidad de Articulos: 500
Stock Minimo: 5
Costo por Pedido: 20
Costo por Unidad Perdida: 5
Costo por Almacenamiento: 10