java

 

GraphConversionProject

 

Overview

 

Forthisprojectyouwillwriteaprogramwhichconvertsagraphstoredusinganadjacency matrixtoagraph storedusingadjacency lists.  Agraphisasetofverticesandasetofedges.  Figure1isanexampleofagraph withthecirclesrepresenting theverticesandthelinesconnecting verticesrepresenting theedges.  Twovertices are adjacenttoeachotherifthere isanedge connectingthetwovertices.  Forexample,verticesAandEinthe graphoffigure 1are adjacent.  Avertexcanbeadjacenttoitselfifthereis anedgewhichstartsandendsatthat same vertex.

 

 

 

A                                           E

 

 

 

 

B                                            D

 

 

 

 

C

 

 

Figure1.

 

Anadjacencymatrixisonemethodofrepresenting theedgesofagraphinacomputerprogram.  Thenumberof columnsintheadjacencymatrixisequaltothenumberofrowsintheadjacencymatrix.   Eachrowinthe adjacencymatrixcorrespondstoauniquevertexinthegraph.   Eachcolumnintheadjacencymatrixalso corresponds toauniquevertexin thegraph.

 

Eachelementintheadjacencymatrixhasavalueof0or1.  Avalueof0fortheelementmeansthere isnoedge betweenthevertexthatrepresentstheelement’srowandthevertexthatrepresentstheelement’scolumn.Avalue of 1for the elementmeansthere isanedge betweenthe vertexthatrepresentsthe element’srow andthe vertex thatrepresentstheelement’scolumn.  Theverticesforthegraphinfigure1are:A,B,C,D,andE.  Figure 2is the adjacencymatrixforthe graph in figure1.

 

 

A

B

C

D

E

A

0

1

0

1

1

B

1

0

1

0

0

C

0

1

0

1

0

D

1

0

1

0

0

E

1

0

0

0

0

 

Figure2.

 

Your programwillreadinthenameof eachvertexof thegraph.  Then,your programwillreadinthegraph’s adjacency matrix.  Usingthegraph’slistofverticesandthegraph’sadjacencymatrix,yourprogramwillcreate thegraph’sadjacencylists.  Eachvertexinthegraphhasanadjacencylist.  Theadjacencylistforavertexisa


 

listofalltheverticesadjacenttotheadjacency list’svertex.  Forexample,theadjacency listforvertexAofthe graph in figure1 is:B, D,and E.

 

Creatingtheadjacency listforavertexisasimpleprocess.  Examineeveryelementintherowforthevertexin theadjacency matrix.  Iftheelement’svalueis0,donothingandmoveontothenextelement.  Iftheelement’s valueis1,addthevertexforthatelement’scolumntotheadjacencylist.Forexample,creatingtheadjacencylist forvertexAinthegraphoffigure1usingtheelementsintherowforvertexAintheadjacency matrix.  The elementsinthecolumnsforvertexB,D,andE haveavalueof1.  Therefore,only B,D,andEareaddedtothe adjacencylist forvertexA.


 

Design

 

1.   Theinputtoyour program will be read from a plain textfile called project1.txt.  This is the statementyou’ll

useto open thefile:

 

FileInputStream fstream = new FileInputStream("project1.txt");

 

Assumingyouare usingEclipsetocreateyourproject,you’llstoretheinputfileproject1.txt intheparent directoryofyoursourcecode, .javafiles,which happenstobethemaindirectoryofyourprojectinEclipse. Ifyou’reusingsomeother developmentenvironment,you’ll haveto figureout whereto storethe input file.

 

Thefirstlineintheinputfilecontainsthenamesoftheverticesofthegraphwitheachnameseparatedby 1 or morespaces.  Starting on the second lineof theinputfileis the adjacencymatrixforthegraph, thesecond lineintheinputfileisthefirstrowoftheadjacencymatrix,thethirdlineintheinputfileisthesecondrow oftheadjacencymatrix,andsoforth.Theorderofthevertexnamesinthefirstlineoftheinputfilecorrespond to therows and columns in the adjacencymatrix.Thefirst vertexname corresponds to the first rowand first columnintheadjacencymatrix,thesecondvertexnamecorrespondstothesecondrowandsecondcolumn in the adjacencymatrix, and so forth.  Each value(0 or1) onalineis separated by1 ormorespaces.

 

Hereisasampleinputfile,   project1.txt,whichwouldbetheinputfilefor thegraphinfigure1.  Youshould createyourownexamplegraphsandtheirinputfiletoproperly testyourprogram.  Yourprogramshould makesuretheinputdoesnotproperly formatted.  Iftheinputisnotproperly formatted,youcouldproperly terminate theprogram and let the user know aboutthe input error.

 

2.   Makethe name of thedriver class Project1and itshould onlycontain onlyonemethod:

pub l ic staticvoidmain(String args[]).

Themain method willopen the file project1.txtand hand off theinputto another class orclasses toperform the graph conversion process.  Therefore, themain methoditself should be fairlyshort.

 

3.   Writeaclasscalled Vertexwhichstoresthenameofavertexinthegraph.The onlymethodsoftheJobclass aretheget and set methods forthevertexname, the toStringmethod, and the constructorforthe class.

 

4.   Downloadthefile   DoublyLinkedList.javacontainingmostoftheimplementationofthedoublylinkedlist class.  Youcannotadddatamemberstoormodifythedatamembersofthedoubly linkedlistclass.  You cannotmodify thenestedprivateclass Nodeofthedoubly linkedlistclass.  Youcannotmodify thenested privateclass LinkedListIteratorofthedoublylinkedlistclass.  Youcannotmodify thedoublylinkedlist classconstructorandthe clear, size, isEmpty, add(AnyType newValue), remove(int index), iterator,and getNode(int index)methods.

 

Youwillwritethecodeforthe getNode(intindex,intlower,int upper)method.  Thismethodreturnsthe pointertothenodewhosepositioninthelistcorrespondtothevalueoftheparameterindex.  This method shouldensure indexisa valuewhichisgreater thanor equaltotheparameter lower andlessthanorequalto the parameterupper.  Ifneeded,you canwrite additionalmethodstohelpinyour implementationof this getNodemethod but theymustbedefined as private.

 

Youwillwritethecodeforthe add(intindex,AnyTypenewValue), remove(Node<AnyType>currNode), get,and setmethods.EachofthesemethodswilluseoneofthegetNodemethods.Recallfortheaddmethod, theindexcanbeavaluefrom0tosize().   Ifneeded,youcanwriteadditionalmethodstohelpinyour implementation of each of thesemethods but theymustbedefined as private.


 

 

 

5.   Yourprogramwillreadinthegraphfromtheinputfile,converttheadjacencymatrix intotheadjacencylists, oneadjacencylist(adoublylinkedlistofvertices)foreachvertex,andfinallyprinttheadjacencylistforeach vertex.

 

6.   Do NOTuseyourownpackagesinyourprogram.  Do NOTuseanygraphicaluserinterfacecodeinyour program.

 

7.   Makeyourprogramasmodularaspossible,notplacingallyourcodeinone.javafile.  Youcancreateas manyclassesasyouneedinadditiontotheclassesdescribedabove.  Methodsshouldbereasonably small followingtheguidancethat "Afunction should do onething, and do itwell."

 

8.   Document and commentyourcodethoroughly.

 


 

Answers

Related Questions

Accounting : Statement Of Cash Flow...

1Running Head: Statement of Cash FlowStatement of Cash FlowStudent name:Institutional affiliation:2Statement of Cash FlowStatement of Cash FlowStateme...

Writing : C442 Project Charter Template 1 2...

Project CharterPart 2Project OverviewProject Description1Project Heart is a project on introducing electronic health records (EHR) in our hospital org...

Business Law : The Unites States Presidential Elec...

Running head: UNITED STATES PRESIDENTIAL ELECTIONSThe Electoral College in U.S. Presidential ElectionsNameInstitution Affiliation:Date:1UNITED STATES...

Accounting : Days In Inventory...

Running Head: Days in Inventory1Days in InventoryInstitutional AffiliationDateDays in Inventory2365 Days in Inventory = But inventory turnover is calc...

Business Law : Case Citation 3...

Running Head: CASE CITATION1Case CitationNameInstitution of AffiliationDateCASE CITATION2Case Citation: Gonzalez v. Oregon, 546 U.S. 243(2006)Parties:...

Business : Small Paragraph...

Insert Surname1Name:University:Course:Time:Date:Importance of project budgetIntroductionA project budget is the amount of money and resources that are...

History : Human Figure In Art...

Running Head: HUMAN FIGURE IN ART1Human Figure in Art:North European, Early, and Italian Renaissances ChangesStudents NameProfessorCourseDateNORTH EUR...

Business : Starb.edited...

Running head: ORGANIZATIONAL BEHAVIORORGANIZATIONAL BEHAVIOR:Name:Institution affiliation:Date:1ORGANIZATIONAL BEHAVIOR2IntroductionFor every single e...

Accounting : Terminology And Stakeholders Workshee...

Terminology and StakeholdersHCS/385 Version 3University of Phoenix MaterialTerminology and StakeholdersDefine the following terms using your text or o...

Powerpoint : Dfg...

BARINGS BANK COLLAPSEA BackgroundAnalogyLeeson was appointed assistant director and generalmanager of BFS on 28 June 1993. He took charge of notonly t...

Computer Science : L416 Answer.edited...

Running head: TECHNOLOGY AND CYBERSECURITYTechnology and CybersecurityStudent NameInstitutional Affiliation1TECHNOLOGY AND CYBERSECURITY2Technology an...

Engineering : Electrical Circuit Lab Report Fig 1...

Part 1InputOutput-10.040.00-9.080.00-8.010.00-6.990.00-5.980.00-5.020.00-4.000.00-3.030.00-2.020.00-1.280.00-0.200.001.250.652.021.383.062.914.013.835...

Computer Science : Linux Security 1...

Surname 1Student NameInstitutional AffiliationCourseInstructorDatePart oneLinux securityWhat is SSH and the advantages and disadvantages of using it o...

Economics : Principles Of Economics...

Running head: PRINCIPLES OF ECONOMICSPrinciples of EconomicsInstitution AffiliationInstructors NameStudents NameCourse CodeDate12PRINCIPLES OF ECONOMI...

Computer Science : Mitigation And Deterrent Techni...

Running head: MITIGATION AND DETERRENT TECHNIQUESMitigation and Deterrent TechniquesCourse nameProfessors nameUniversity nameDate1MITIGATION AND DETER...

Health & Medical : Unit Iv Research Paper...

Running head: PRESCRIPTION DRUG OVERDOSEPrescription Drug OverdoseNameCourseProfessorDate1PRESCRIPTION DRUG OVERDOSE2Prescription Drug OverdoseTypes o...

Writing : Immigration Policy.edited...

Running head: IMMIGRATION POLICYImmigration PolicyStudents Name:University Affiliation:1IMMIGRATION POLICY2Immigration policyImmigration policies have...

Business : R352 Ethical Discussion...

Running head: ETHICAL DISCUSSION1Ethical DiscussionInstitution AffiliationDateETHICAL DISCUSSION2Question 1Reputation management entails presenting in...

Political Science : Political Parties...

Surname 1Name of studentName of tutorCourseDateAffirmative ActionsLink: https://edition.cnn.com/2015/02/17/politics/texas-Obama-immigrationinjunction/...

History : 9089992...

Surname 1Student's NameProfessor's NameCourse TitleDue DateHistory of ChinaEssay 1:You are having dinner with a group of friends in a restaura...

Social Science : Maria...

Marias Case Study DiscussionMarias story narrates the events in her life during the late adolescence and the earlyyoung adulthood. According to Erik E...

Writing : Anthropology 3...

1Running Head: ANTHROPOLOGYAnthropologyStudentInstitutionANTHROPOLOGY2Audra Simpson in her article `From Mohawk Interruptus` gets to discuss various a...

Health & Medical : Migraine Treatment.edited...

Running head: MIGRAINE TREATMENT1Migraine Treatment(Name)(Course)(Date)MIGRAINE TREATMENT2Migraine TreatmentMigraines represent a select group of unus...

Writing : Anthropology 2...

Running Head: ANTHROPOLOGY1AnthropologyStudentInstitutionANTHROPOLOGY2Audra Simpson`s article `From Mohawk Interruptus` is an article that is portrayi...

If you didn't find the right answer

Ask Your Questions, We'll notify you once someone answers it