811312A Tietorakenteet ja algoritmit 2016-2017, Python-kielinen harjoitustyö Tämä harjoitustyö toteutetaan Python-kielellä. Monet matkustajat saapuvat Ouluun käyttäen useiden matkatoimistojen palveluja. Eräs oululainen yritys haluaa luoda tehokkaan järjestelmän matkanjärjestäjiltä kerätyn tiedon hallitsemiseksi. Sinun tehtäväsi on implementoida osa tästä järjestelmästä; tiedot tallennetaan ohjelmassa kahteen binääriseen etsintäpuuhun ja kahdentyyppisiin linkitettyihin listoihin. Alkutiedot luetaan ohjelmaan neljästä tiedostosta. Muokattujen tietojen tallennusta tiedostoihin ei tarvitse toteuttaa. Ensimmäiseen listaan tallennetaan tiedot matkatoimistoista. Listan jokainen solmu sisältää seuraavat tiedot: Tunnus (Yksikäsitteinen) Nimi Rekisteröintipäivä Henkilökunnan lukumäärä Johtajan nimi Solmut lajitellaan tunnuksen perusteella. Ohjelman aluksi tiedot luetaan tekstitiedostosta (agencies.txt); tiedoston jokainen rivi kuvaa matkatoimistoa. Rivillä ovat yllämainitut kentät mainitussa järjestyksessä tabulaattorilla erotettuina. Päivämäärät esitetään tässä työssä muodossa vvvv.kk.pp. Ensimmäinen binääripuu sisältää asiakkaiden tiedot. Puun jokaisessa solmussa säilytetään sitä vastaavasta asiakkaasta seuraavia tietoja: Tunnus (jokaiselle asiakkaalle yksikäsitteinen) Nimi Puhelinnumero Osoite Tunnusta käytetään asiakkaan paikan määräytymiseen puussa (sitä käytetään siis puun solmujen avaimena). Ohjelman aluksi tiedot luetaan tekstitiedostosta (customers.txt); tiedoston jokainen rivi kuvaa asiakasta. Rivillä ovat yllämainitut kentät mainitussa järjestyksessä tabulaattorilla erotettuina. Toinen binääripuu sisältää matkatoimistojen kuljettajien tiedot. Kuten asiakkaiden tapauksessa, puun solmussa säilytetään yhden kuljettajan tietoja: Tunnus (jokaiselle kuljettajalle yksikäsitteinen) Nimi Työhön ottamisen päivä Automalli
Tässäkin tapauksessa tunnusta käytetään puun solmujen avaimena. Ohjelman aluksi tiedot luetaan tekstitiedostosta (drivers.txt); tiedoston jokainen rivi kuvaa kuljettajaa ja rivi on seuraavaa muotoa: Kuljettaja_tunnus Kuljettajan_toimisto_tunnnus Nimi Palkkauspäivä Automalli Rivin kentät on erotettu tabulaattoreilla. Huomaa, että koska jokainen kuljettaja on jonkin matkatoimiston palkkaama, rivin toinen kenttä on matkatoimiston tunnus. Jokaisella kuljettajalla on oma listansa, jossa säilytetään tietoja hänen toimittamistaan palveluista (matkoista). Jokaiseen kuljettajaan siis liittyy linkitetty lista, jonka solmuissa ovat seuraavat tiedot: Tunnus (kullekin matkalle yksikäsitteinen) Matkan päivä ja kellonaika Asiakkaan tunnus Lähtöpaikka ja päämäärä Saatu palkkio (euroissa) Ohjelman aluksi tiedot luetaan tekstitiedostosta (travels.txt); tiedoston jokainen rivi kuvaa matkaa ja rivi on seuraavaa muotoa: Matkan_tunnus Kuljettajan_tunnus Päivä_ja_aika Asiakkaan_tunnus Lähtöpaikka Päämäärä Palkkio Rivin kentät on erotettu tabulaattoreilla. Huomaa, että koska jokainen matka liittyy kuljettajaan, rivin toinen kenttä on matkan suorittaneen kuljettajan tunnus. Ohjelmaan on toteutettava seuraavat toiminnot: Matkatoimiston etsiminen nimen tai tunnuksen perusteella Kuljettajan etsiminen nimen tai tunnuksen perusteella Asiakkaan etsiminen nimen tai tunnuksen perusteella Palveluoperaatiot: matkan lisääminen, poistaminen ja etsiminen Käytä ohjelmasi pohjana tiedostoja Classes.py ja main.py jotka sisältävät matkatoimistojen tietojen lataamiskoodin. Ohjelmaan tulee toteuttaa seuraavat funktiot: Funktio, joka muodostaa listan annetun asiakkaan saamista palveluista (tehdyistä matkoista) aikajärjestyksessä. Funktio, joka muodostaa listan asiakkaista, jotka ovat hankkineet palveluita annettujen päivämäärien välisenä aikana. Funktio, joka muodostaa listan kuljettajista, jotka ovat palvelleet annettua asiakasta (tunnistetaan asiakastunnuksen perusteella). Kuljettajat listataan järjestyksessä nimen perusteella. Pyri käyttämään mahdollisimman tehokasta tapaa saada em. tulokset.
Arvioi funktioittesi aikakompleksisuutta matkatoimistojen, asiakkaiden, kuljettajien ja matkojen lukumäärän suhteen. Mittaa myös ohjelmasi suoritusaikoja testisyötteillä ja arvioi ovatko ne yhdenmukaisia analyysisi kanssa. Ohjelmakoodin lisäksi palautetaan työselostus, jossa kuvataan 1. ratkaisu ja 2. ohjelman suorituskyvyn analyysi, kuten edellä mainittiin. Analyysi sisältää siis käytettyjen algoritmien analyysin ja ohjelman suoritusaikojen mittaukset. Ohjelmakoodin tulee olla asiallisesti kommentoitu, mutta muuta dokumentointia ei vaadita. Työselostukseen liitetään luonnollisesti myös nimi ja opiskelijanumero. Mikäli haluat, voit antaa työselostuksessa myös palautetta työstä, esimerkiksi tehtävään käytetty työmäärä, työn helpot ja hankalat asiat ja mitä opit työtä laatiessasi. Muutakin palautetta voi antaa. Muista pakata tiedostot yhdeksi pakkaukseksi ennen palauttamista. Tehtävän ratkaisu on palautettava viimeistään 15.2.2017.
811312A Data Structures and Algorithms 2016-2017, Python Assignment This assignment shall be implemented in Python. In Oulu, many passengers arrive in their destinations using services provided by multiple travel agencies. A team in Oulu wants to manage and control these agencies by collecting different sets of data from them. Hence, this team intends to create an efficient system to collect, store and manipulate their data. In this assignment, you have to implement a part of such a system. This system should be implemented using two binary search trees and two linked lists. The initial data are read from four different files. You do not need to implement storing of manipulated data. The first list stores the information about the travel agencies. Each node in this list contains the following information: ID Unique Name Registration Date Number of staff members Manager s name The nodes in this list should be sorted based on the ID. Initially the agencies are read from a text file (agencies.txt); each line represents an agency with the fields separated by tabulators. The fields are stored in the order presented above. Dates are represented in the form yyyy.mm.dd in this assignment. The first binary tree only includes the information for customers. Each node in this tree represents a customers with the following information: ID unique for each customer Name Phone number Address ID is used as the key to decide the correct place for each customer (The tree is sorted based on the customer ID). Initially the customers are read from a text file (customers.txt); each line represents a customer with the fields separated by tabulators. The fields are stored in the order presented above. The second binary tree contains the information for the drivers in each travel agency. Similar to the previous case, each node in this tree represents a driver with the following information: ID unique Name Hiring Date Car model
Similarly, ID is used as the key for this tree as well. Initially the drivers are read from a text file (drivers.txt); each line represents a driver and lines are of form Driver_ID Driver_Agency_ID Name Hiring_Date Car_model with the fields separated by tabulators. Note that, because a driver belongs to an agency, the second field is the agency s ID. The fields are stored in the order presented above. Every node in the first linked list contains instances of these two binary search trees with the specific information obtained from them. Different agencies do not have access to the customer and driver data from the other agencies (other nodes in the linked list). Each driver has a list of his own, containing the information regarding his/her services (travels). This is the second linked list that should be implemented in this project. Every driver node in the driver binary tree should have a linked list member containing the following information: ID unique travel id travel Date and time customer ID Source and destination Received amount (euros) Initially the travels are read from a text file (travels.txt); each line represents a travel and lines are of form Travel_ID Driver_ID Date_and_time Customer_ID Source Destination Payment_amount with the fields separated by tabulators. Note that, because a travel is associated with a driver, the second field is the driver s ID. The fields are stored in the order presented above. This program should be able to do the following: Agency operations: search for an agency Driver operations: search for a driver Customer operations: search for a customer Driver services operations: add service, delete service, search for a service Use as a basis the files Classes.py and main.py that contain code for loading the agencies file. The following should be implemented by you: Write a function that shows the number of services requested by a customer, sorted by date. Write a function that shows the list of customers who have received services from different agencies from date 1 to date 2 sorted by date. Write a function that shows the list of drives who have served a specific customer (search by ID) sorted by the driver names.
In each case use efficient data structures and algorithms for returning the results. Estimate the time complexity of the functions, in terms of the number of agencies, customers, drivers and travels. Also, measure the running times of your functions with test inputs try to deduce if your estimate and measurements are in concordance. In addition to program code, you shall return a report that describes 1. the solution, and 2. analysis of program s performance as mentioned above. Analysis contains thus the analysis of the used algorithms and the measurements of program s running times. The code shall be commented but no other documentation is required. The report shall naturally contain student s name and student number. If you wish, you can also give feedback in your report. Remember to zip the files before returning. The assignment shall be returned by 15.2.2017.