1 / 66

RAS Software Architecture & Development methodology : (via the TSP Exercise)

RAS Software Architecture & Development methodology : (via the TSP Exercise). Melvin, Max, and Hon Wai (2008) based on notes from ShuaiCheng (2003) Chong Ket Fah and Ning Kang (2005) Chong Ket Fah, NingKang and Melvin (2006). Outline. Overview and Purpose TSP problem

lee-rocha
Download Presentation

RAS Software Architecture & Development methodology : (via the TSP Exercise)

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. RAS Software Architecture & Development methodology : (via the TSP Exercise) Melvin, Max, and Hon Wai (2008) based on notes from ShuaiCheng (2003) Chong Ket Fah and Ning Kang (2005) Chong Ket Fah, NingKang and Melvin (2006)

  2. Outline • Overview and Purpose • TSP problem • TSP System Architecture • Data & Parameter files • Exercises • Program & Coding Standard • Using SVN and Getting Started

  3. Overview and Purpose • Understand RAS Software Methodology • (as defined in the RAS-handbook) • Using TSP as an example • to show methodology at work

  4. Principles behind the RAS Architecture • Allow seamless integration of multiple algorithms (solvers) • Allow independent,concurrent development by several students • Support fast, automated evaluation of several algorithms

  5. Principles behind the RAS Architecture (continued…) • Common, consistent software style and standards • enhance code understanding and maintainability • Enhance reusability • across multiple batches of students

  6. Outline • Overview and Purpose • TSP problem • TSP System Architecture • Data & Parameter files • Exercises • Program & Coding Standard • Using CVS

  7. Traveling Salesman Problem • Given the positions of N cities, what is the shortest closed tour in which each city is visited exactly once? • Problem is NP-complete • Some References: • http://www.tsp.gatech.edu//index.html • http://itp.nat.uni-magdeburg.de/~mertens/TSP/TSP.html

  8. Algorithms For TSP • Nearest Neighbour Heuristic • Closest Insertion Heuristics • 2-opt Exchange Heuristics • Many others too: (for your ref…) • 2.0 Approximation Algorithm • Furthest Insertion Heuristic • Edge Insertion Heuristic • Simulated Annealing

  9. Nearest Neighbour heuristic • Start with any vertex v • While (not all the vertices are visited) do • Select unvisited vertex u that is nearest to v; • Add edge (v,u) to T; • v  u; Animation: (nearest neighbour heuristics) http://itp.nat.uni-magdeburg.de/~mertens/TSP/TSP.html

  10. Closest Insertion heuristic • Start with a partial tour T of a single vertex v • While (not all the vertices are in the tour) • Select an unused vertex u such that the distance from u to a vertex v in T is minimum • Insert u into the tour T (by connecting v to u) • Question: What initial tour T to start with? • Note: There are other variations too… Animation: (Cheapest Insertion from Convex Hull) http://itp.nat.uni-magdeburg.de/~mertens/TSP/TSP.html

  11. 2-opt Exchange Heuristics • Start with a any TSP tour T ; • While (there is improvement) do • “Exchange” two edges e1 and e2 in tour T to decrease the length of the tour Note: O(n2) pairs of edges to consider each iteration Animation: (2-opt exchange heuristics) http://itp.nat.uni-magdeburg.de/~mertens/TSP/TSP.html

  12. 2 Approximation Algorithm Algorithm Overview • Construct the minimal spanning tree • Duplicate all its edges. This gives us an Euler cycle. • Traverse the Euler cycle, skipping already visited nodes.

  13. 2.0 Approximation Algorithm

  14. Furthest Insertion heuristic • Start with a partial tour T of a single vertex v • While (not all the vertices are in the tour) • Select an unused vertex u such that the minimum distance from u to a vertex v in T is maximum • Insert u into T such that the increase in the length of the tour is minimum

  15. Edge Insertion Heuristic • Sort the edges (in increasing edge weights) • T  { }; • Scan edge e (in increasing cost) and add edge e to T only if T  {e} • does not form a cycle (unless |T|=n). • does not have vertex of degree three or more

  16. Simulated annealing • S = random tour • t = some large number // initial “temperature” • repeat • randomly swap two edges of the tour S to obtain S’ • change = cost(S) – cost(S’) • if change > 0 then • S = S’ • else • x := random (0,1); • if (x < exp(-change/T)) thenS = S’ • T = a * T; // choose a between 0.8 and 0.99 • until stopping condition

  17. Outline • Overview and Purpose • TSP problem • TSP System Architecture • Data & Parameter files • Exercises • Program & Coding Standard • Using CVS

  18. RAS Software Design • TSP Software architecture diagram • TSP Class diagram • File formats and related issues: • TSP project file, parameter files • TSP Input/output data formats • use the RAS-standards, unless std exists • Sample files

  19. RAS Software Architecture Template

  20. Principles behind the RAS Architecture • Separate domain classes (package) from algorithms classes (solvers) • Separate engine from GUI • Separate datafiles/database from domain and algorithms classes

  21. TSP Solver TSP Package TSP Solver Components TSP Classes High Level TSP System Architecture User Interface Library Components

  22. TSP System Design TSP Engine TSP Package Data Sources GUI Module TSP Solver TSPCI Solver TSPNN Solver TSP2OptSolver

  23. TSP Package • Encode the TSP Domain objects • Provides important interface methods • Entire package is sent to solvers • Solvers updates info inside package • Package read from / write to DB

  24. TSP Solver Class(es) • Suppose there is only 1 algorithm • One solver class is enough • What if there are several algorithms?

  25. Our TSP Solver Class • TSP Solver Class is a “generic” solver • It is used to “call” different algorithms • Each algorithm is • Implemented as a different solver class • Done by different people • But uses the standard TSP Package • Then, integrate into the generic TSP Solver class

  26. TSP Engine TSP Package GUI Module TSP Solver CISolver NNSolver 2-OptSolver TSP Package Class Data Sources Parameter Files Project File ReadProjFile() – interface to initiate reading of data and parameters files as specified in project file

  27. Show the TSPPackage.h file

  28. TSP Engine TSP Package GUI Module TSP Solver CISolver NNSolver 2-OptSolver TSP System Architecture -Interface Input - TSPSolver::TSPSolver(TSPPackage& aPackage) Interface - TSPPackage::GetSolverVersion() TSPPackage::GetCostRepOpt() TSPPackage::GetCostMatrix() …

  29. TSP Engine TSP Package GUI Module TSP Solver CISolver NNSolver 2-OptSolver TSP Solver Class Solve() – Determines algo to use, and instantiate and run algo (call Solve() function in particular algo). WriteSolutionFile() – Write solution in file which can be read by GUI Module and the results displayed

  30. Show the TSPSolver.h file

  31. TSP Engine TSP Package GUI Module TSP Solver CISolver NNSolver 2-OptSolver TSPSolver calling different Solvers Input – TSPNNSolver::TSPNNSolver (TSPPackage& aPackage, vector<int>* aSolution) Interface – Specific solver read data and internal representation parameters from interface functions in TSPPackage

  32. TSP Engine TSP Package GUI Module TSP Solver CISolver NNSolver 2-OptSolver Running with different Solvers solve() – Run specific algorithm that solver represents and store result in solution representation (aSolution)

  33. Show the TSPSolver.cc file

  34. TSP Solver Class … void TSPSolver::Solve() // the generic solve() method { if (mPackage.GetSolverVersion()=="CIG") {… TSPCIGSolver solver(mPackage, mSolution); solver.Solve(); } else if (mPackage.GetSolverVersion()=="NNG") { … TSPNNGSolver solver(mPackage, mSolution); solver.Solve(); } else if (mPackage.GetSolverVersion()=="2OPTM") { … } }

  35. Main Program #include "TSPPackage.h“ // include important stuff used #include "TSPSolver.h" int main(int argc, char* argv[]) { if (argc!=2) // CHECK command-line arguments!! {…} …. TSPPackage myTSPPackage(ProjectFile); // Initializes the TSPPackage TSPSolver myTSPSolver(myTSPPackage); // Initializes the Solver myTSPSolver.Solve(); // Invokes Solve() method and …. // Update solution to TSPPackage return 0; }

  36. Outline • Overview and Purpose • TSP problem • TSP System Architecture • Data & Parameter files • Exercises • Program & Coding Standard • Using CVS

  37. Data & Parameter files • Data File – city.dat • Parameter File – default.para • Solution File – solution000.dat • Other files: • Summary file • Trace files

  38. Sample city.dat file _NUM_CITIES 27 _CITY_LOCATION 0 14.0 27.0 1 2.0 31.0 2 35.0 30.0 3 11.0 17.0 4 0.0 7.0 5 39.0 29.0 6 16.0 29.0 7 3.0 49.0 8 40.0 40.0 9 26.0 32.0 10 29.0 32.0 11 14.0 15.0 12 11.0 23.0 13 25.0 38.0 14 23.0 40.0 15 43.0 37.0 16 18.0 46.0 17 19.0 5.0 . . . _END

  39. Parameter File _COST_REPRENTATION_FORMAT #0 means use a graph #1 means use a mattix 0 _SOLVER_VERSION NNG _END

  40. Solution File _SOLUTION 0 6 26 19 9 18 10 2 5 15 8 13 14 16 25 23 24 1 27 12 3 11 21 4 17 20 22 7 _COST 263.852

  41. Outline • Overview and Purpose • TSP problem • TSP System Architecture • Data & Parameter files • Exercises • Program & Coding Standard • Using CVS

  42. Exercises • Write your own new TSPSolver • Choose any algorithm you like • Some possibilites: • Further insertion, simulated annealing, your own heuristics • Integrate your TSPSolver • Need to modify “some parts of the code” • Create new project and parameter files

  43. Exercises (optional…) • To help clean up the TSP code… • Architecture • Modify TSPPackage and TSPSolver • Write the solution into TSPPackage class • Move the function of writing the solution to the output file from the TSPSolver class to the TSPPackage class • Make all solvers to be subclass of an abstract TSPSolver class [done?] • Rectify issue of graph rep (Matrix vs Adj list) • Others?

  44. Outline • Overview and Purpose • TSP problem • TSP System Architecture • Data & Parameter files • Exercises • Program & Coding Standard • Using CVS

  45. Coding Standard See other ppt file (by David Ong) To be updated… • All names must be alpha-numeric strings. All characters are in lower case, with uppercase being used to separate a multi-word variable. • int myLocalVariable, callMyFunction, CallAFunction • Class name begin with an upper case • Class Variable start with m (stand for member)

  46. Coding Standard See other ppt file (by David Ong) To be updated… • Function argument are prefixed with ‘a’ • Eg: fun(int aTime) • Avoid global variables • If really necessary, start with Global • Eg: GlobalVariable

  47. Outline Overview and Purpose TSP problem TSP System Architecture Data & Parameter files Exercises Program & Coding Standard Using SVN

  48. Using SVN SVN (Subversion)is a version control system Intended as a replacement for CVS Enables multiple developers to work on the same project Keep track of changes to files and allows developers to rollback to a previous version Basic concepts Checking out a repository Updating your working copy Adding/removing files to/from the repository Committing changes to the repository

  49. Using SVN (II) Checking out a repository Browse to a folder that you want to store the branch (e.g. TSP/branches/) $ svn co <repository_name> $ svn co http://ras-5.ddns.comp.nus.edu.sg/svn/TSP/branches/TSP-<yourunixname> Updating your working copy $ svn update Recursively updates the current directory and all subdirectories

  50. Using SVN (III) Adding/removing files to/from the repository Create the file in your working copy $ svn add <filename> Delete the file from your working copy $ svn remove <filename>

More Related