def test_encolar_tamano(self):
     cola = Cola()
     for unidad in range(10):
         cola.encolar(unidad)
     tamanoEsperado = 10
     tamanoObtenido = cola.tamano
     self.assertEqual(tamanoEsperado, tamanoObtenido)
 def test_cola_representacion(self):
     cola = Cola()
     for numero in range(1, 11):
         cola.encolar(numero)
     representacionEsperada = str([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
     representacionObtenida = cola.__repr__()
     self.assertEqual(representacionEsperada, representacionObtenida)
Esempio n. 3
0
class ColaDePacientes:
    def __init__(self):
        self.pacientes=Cola()
    def nuevo_paciente(self,nombre):
        self.pacientes.encolar(nombre)
    def proximo_paciente(self):
        return self.pacientes.desencolar()
 def test_encolar_fin(self):
     cola = Cola()
     for unidad in range(10):
         cola.encolar(unidad)
     finColaEsperado = 9
     finColaObtenido = cola.finCola.elemento
     self.assertEqual(finColaEsperado, finColaObtenido)
 def test_encolar_inicio(self):
     cola = Cola()
     for unidad in range(10):
         cola.encolar(unidad)
     inicioColaEsperado = 0
     inicioColaObtenido = cola.desencolar()
     self.assertEqual(inicioColaEsperado, inicioColaObtenido)
 def test_desencolar(self):
     cola = Cola()
     for unidad in range(10):
         cola.encolar(unidad)
     elementoEsperado = 0
     elementoObtenido = cola.desencolar()
     self.assertEqual(elementoEsperado, elementoObtenido)
     for unidad in range(3):
         cola.desencolar()
     elementoEsperado = 4
     elementoObtenido = cola.desencolar()
     self.assertEqual(elementoEsperado, elementoObtenido)
Esempio n. 7
0
class TorreDeControl:
    def __init__(self):
        self.aterrizar = Cola()
        self.despegar = Cola()

    def reconocimiento(self):
        for x in range(random.randrange(2)):
            self.aterrizar.encolar('avion')
        for x in range(random.randrange(2)):
            self.despegar.encolar('avion')

    def accion(self):
        if len(self.aterrizar) < len(self.despegar):
            return self.despegar.desencolar()
        else:
            return self.aterrizar.desencolar()

    def __str__(self):
        return 'Hay {} aviones esperando para aterrizar y {} para despegar'.format(
            len(self.aterrizar), len(self.despegar))
Esempio n. 8
0
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#
#

from Cola import Cola

cola = Cola()

cola.push(12)
cola.push(23)
cola.push(56)
cola.push(78)
cola.show()
cola.pop()
cola.pop()

cola.show()
cola.front()
Esempio n. 9
0
 def __init__(self):
     self.pacientes=Cola()
Esempio n. 10
0
import curses
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
from random import randint
from ListaCircular import ListaCircular
from Cola import Cola
import csv

#este es el menu que subio de ejemplo el aux Dennis a github
import curses #import the curses library
import time
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN #import special KEYS from the curses library
listac=ListaCircular()
cola=Cola()
def paint_menu(win):
    paint_title(win,' MAIN MENU ')          #paint title
    win.addstr(7,21, '1. Play')             #paint option 1
    win.addstr(8,21, '2. Scoreboard')       #paint option 2
    win.addstr(9,21, '3. User Selection')   #paint option 3
    win.addstr(10,21, '4. Reports')         #paint option 4
    win.addstr(11,21, '5. Bulk Loading')    #paint option 5
    win.addstr(12,21, '6. Exit')            #paint option 6
    win.timeout(-1)                         #wait for an input thru the getch() function

def paint_title(win,var):
    win.clear()                         #it's important to clear the screen because of new functionality everytime we call this function
    win.border(0)                       #after clearing the screen we need to repaint the border to keep track of our working area
    x_start = round((60-len(var))/2)    #center the new title to be painted
    win.addstr(0,x_start,var)           #paint the title on the screen

def wait_esc(win):
    key = window.getch()
Esempio n. 11
0
'''
Cola

Es una estructura de datos, caracterizada por ser una secuencia de elementos en la que la operación de insercion (push) se realiza por un extremo y la operacion de extraccion (pop) por el otro. También se le llama estructura FIFO (del inglés First In First Out), debido a que el primer elemento en entrar será también el primero en salir.

OPERACIONES: 
- Insertar
- Eliminar
- Buscar
- Estado de la cola (vacía o con elementos)
- Retornar elemento frontal
- Retornar el tamaño de la cola
- Etc
'''

from Cola import Cola

cola = Cola()

cola.push(12)
cola.push(34)
cola.push(35)
cola.push(17)
cola.push(36)

cola.show()

cola.pop()
print('--------------------------------')
cola.show()
Esempio n. 12
0
 def test_colaVacia(self):
     cola = Cola()
     self.assertTrue(cola.colaVacia())
     elemento = 1
     cola.encolar(elemento)
     self.assertFalse(cola.colaVacia())
Esempio n. 13
0
 def __init__(self):
     self.eventos = Cola()
Esempio n. 14
0
    return tb.gather()


def textpadCarga():
    inp = curses.newwin(8, 55, 0, 0)
    inp.addstr(1, 1, "Ingrese direccion archivo csv: ")
    sub = inp.subwin(3, 41, 2, 1)
    sub.border()
    sub2 = sub.subwin(1, 20, 3, 2)
    tb = curses.textpad.Textbox(sub2)
    inp.refresh()
    tb.edit()
    return tb.gather()


Puntos = Cola()
GuardarScore = Pila()
serpiente = ListaDoble()

menu = ListaCircularDoble()
menu.agregar_inicio('Davis')

stdscr = curses.initscr()  #initialize console
window = curses.newwin(25, 80, 0, 0)  #create a new curses window
window.keypad(True)  #enable Keypad mode
curses.noecho()  #prevent input from displaying in the screen
curses.curs_set(0)  #cursor invisible (0)
paint_menu(window)  #paint menu

keystroke = -1
while (keystroke == -1):
Esempio n. 15
0
import json
from flask import Flask
# from flask import request
from ListaSimple import ListaSimple
from Cola import Cola
from Pila import Pila
from Matriz import Matriz

app = Flask(__name__)
mLista = ListaSimple()
mCola = Cola()
mPila = Pila()
mMatriz = Matriz()


@app.route('/')
def hello_world():
    return 'Practica2'


@app.route('/lista/agregar/<dato>')
def listaAgregar(dato):
    mLista.agregarAlFinal(dato)
    return json.dumps({"success": True})


@app.route('/lista/buscar/<dato>')
def listaBuscar(dato):
    x = mLista.buscar(dato)
    return json.dumps({"index": x, "success": True})
Esempio n. 16
0
 def __init__(self):
     self.aterrizar = Cola()
     self.despegar = Cola()
Esempio n. 17
0
from Cola import Cola


class UsuarioMoto():
    def __init__(self, nombre, apellido, placa):
        self.nombre = nombre
        self.apellido = apellido
        self.placa = placa


cola = Cola()
colaAux = Cola()
colaAux2 = Cola()


def ImprimirCola(cola):
    for i in range(0, cola.longitudCola()):
        print "Nombre: ", cola.getElementoPosCola(
            i).nombre, " Apellido: ", cola.getElementoPosCola(
                i).apellido, " Placa: ", cola.getElementoPosCola(i).placa


print(cola.colaVacia())
cola.agregarElementoCola(UsuarioMoto("Daniela", "Cordoba", "AB123"))
cola.agregarElementoCola(UsuarioMoto("Andrea", "Acosta", "CD456"))
cola.agregarElementoCola(UsuarioMoto("Santiago", "Jimenez", "EF789"))
cola.agregarElementoCola(UsuarioMoto("Camilo", "Bonilla", "GH321"))
print(cola.colaVacia())

usuario = cola.sacarElementoCola()  #Aqui sacamos uno
print "Nombre: ", usuario.nombre, " Apellido: ", usuario.apellido, " Placa: ", usuario.placa
Esempio n. 18
0
def tabu_search(circuito, points):
    aristas = []
    vauxiliar = circuito
    n = len(vauxiliar)

    dis_circuito = calcula_dis_circuito(circuito, points)
    mejor_dis_circuito = dis_circuito
    mejor_circuito = copy.deepcopy(vauxiliar)

    lista_tabu = Cola(n)
    contador = 0
    max_iters = 150
    iter = 0

    while iter < max_iters:
        iter += 1
        divisor = random.randint(1, n - 2)
        aux1 = vauxiliar[:divisor]
        aux2 = vauxiliar[divisor:]
        aux2.extend(aux1)

        vauxiliar = aux2

        mejor_par = []
        mayor_mejora = -math.inf
        for i in range(0, n - 3):
            for j in range(i + 2, n - 1):
                rp1 = length(points[vauxiliar[i]], points[vauxiliar[i + 1]])
                rp2 = length(points[vauxiliar[j]], points[vauxiliar[j + 1]])

                rr = length(points[vauxiliar[i]], points[vauxiliar[j]])
                pp = length(points[vauxiliar[i + 1]], points[vauxiliar[j + 1]])

                mejora = (rp1 + rp2) - (rr + pp)

                if mejora > mayor_mejora:
                    if not lista_tabu.buscar((vauxiliar[i], vauxiliar[j])):
                        mayor_mejora = mejora
                        mejor_par = [i, j]
                        aristas = (vauxiliar[i], vauxiliar[j])

        lista_tabu.insertar(aristas)

        aux_cir1 = vauxiliar[:mejor_par[0] + 1]
        aux_cir2 = vauxiliar[mejor_par[0] + 1:mejor_par[1] + 1]
        aux_cir2.reverse()

        aux_cir1.extend(aux_cir2)

        aux_cir3 = vauxiliar[mejor_par[1] + 1:]
        aux_cir1.extend(aux_cir3)

        vauxiliar = aux_cir1
        dis_circuito = dis_circuito - mayor_mejora

        if dis_circuito < mejor_dis_circuito:
            mejor_dis_circuito = dis_circuito
            mejor_circuito = copy.deepcopy(vauxiliar)
            contador = 0
        else:
            contador += 1

        if contador == 10:
            break

    return mejor_circuito
import random
import logging
import threading
import time

from Cola import Cola

logging.basicConfig(
    format='%(asctime)s.%(msecs)03d [%(threadName)s] - %(message)s',
    datefmt='%H:%M:%S',
    level=logging.INFO)

#cantidadMaximaLatas = 10
#cantidadMaximaBotellas = 15
colaLecturaClientes = Cola()
colaEscrituraClientes = Cola()
colaLecturaProductos = Cola()
colaEscrituraProductos = Cola()

cantMaxHilosLectura = 3

# SI LA PETICION ES DE SOLO LECTURA SI SE PERMITE EJECUTAR MAS DE UN PROCESO
semaforoProducto = threading.Semaphore(cantMaxHilosLectura)
semaforoEscrituraProducto = threading.Semaphore(1)
semaforoCliente = threading.Semaphore(cantMaxHilosLectura)
semaforoEscrituraCliente = threading.Semaphore(1)


class GestorDeTransacciones(threading.Thread):
    def __init__(self, transaccion):
        super().__init__()