1 / 11

Grafuri orientate

Grafuri orientate. Proiect realizat de Caramizoiu Vlad Colegiul National Ecaterina Teodoriu. Aplicatii ale grafurilor in viata reala

binta
Télécharger la présentation

Grafuri orientate

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Grafuri orientate Proiectrealizat de CaramizoiuVlad Colegiul National EcaterinaTeodoriu

  2. Aplicatii ale grafurilor in viatareala Sa presupunem ca esti in Targu-Jiu,esteora 7:45 sivreisaajung la scoalainainte de ora de incepere a cursurilor ,aceastafiindsituata in parteaopusa a orasului .Mai aila dispozitie 15 minute astfel ca singuratasansaestesagaseascidrumulcelmaiscurt.

  3. Intr-un moment de sclipireacestaitidaiseama ca reteauastadala a orasului seaman cu un graforientatsi ca potiulitiza un program C++ pentru a determinadrumulminim. Inainte de o continua povesteasa ne amintimcatecevadespregrafuri.

  4. Grafuri Orientate

  5. Asadartrebuiasarealizezi un algoritm care sacalculezedrumulcelmaiscurt de la tine de acasapana la scoala la care inveti.(Daca nu stiirealizezi un astfel de algoritmesteprobabil din cauza ca tejucai asphalt 8 in timpceprofesoaraexplicagrafurile) Sa presupunem ca fiecarestarda(muchie) in functie de lungimieasa are un anumitcost.Unastfel de program consta in gasirealantului de cost minim ceunestecele 2 puncte . Un grafcaruiais-a asociat o functie cost se numestegrafponderat.Functia cost asociataunaigraf se folosestepentrudeterminareadrumurilor de cost minim existenteintrecele 2 noduri ale graficului.Pentruaceastafiecaruigrafi se asociaza o matricenumitamatriceacosturilor.Matriceacosturilor are 2 variante in functie de scopul in care a fostdefinita.

  6. Pentrudeterminareadrumurilor de cost minim se definestematriceastfel: -M(i,j)=0,daca i=j; - M(i,j)=c(cost),dacai!=j siexista arc de la i la j ; -M(i,j)=∞,dacai!=j sinu exista arc de i la j. Pentrudeterminareacostului minim intre 2 noduri (x si y)se pleaca de la matriceainitiala M si se transformaaceastaasemanatoralgoritmului de obtinere al matriceidrumuriloralegandfiecare nod ca fiind nod intermediarintrealte 2 noduri

  7. Matriceadrumurilor de cost minim se obtine cu algoritmulRoy-Floyd: #include<fstream.h> ifstreamf(“date.in”); ofstreamg(“date.out”); intmain() {f>>n>>m; for(i=1;i<=n;i++) for(f=1;j<=n;j++) if(i==j) a[i][j]=0; else a[i][j]=9999999;

  8. for(i=1;i<=n;i++) {f>>x>>y>>c; a[x][y]=c;} for(k=1;k<=n;k++) for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(a[i][j]>a[i][k]+a[k][j]) a[i][j]=a[i][k]+a[k][j]; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) g<< a[i][j]<<’ ‘; g<<’n’;}}

  9. In final probabil nu veireusiisafaci un program functional ,veiintarzia la scoalaajungandastfel la 10 absente sidrepturmare media ta la purtarevaavea de suferit de suferit. Morala: Fiiatent la ora de informatica ,nu stiiniciodatacand o saititrebuiasca in viata.

More Related