Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3387f603ecf505e1a429cb7e3faa50295930a06f
[mapping.git] / src / and / Mapping / Graph.java
1 package and.Mapping ;
2
3
4 import java.io.Serializable;
5 import java.util.ArrayList;
6
7
8
9
10 /**
11  * Class representing the application's graph
12  * @author Sébastien Miquée
13  */
14 public class Graph implements Serializable
15 {
16         private static final long serialVersionUID = 1L;
17
18         
19         private ArrayList<GTask> graph ;
20 //      private int nb_task ;
21         private int nb_dep_total ;
22         
23         
24         /**
25          * Default constructor.
26          */
27         public Graph()
28         {
29                 graph = new ArrayList<GTask>() ;
30 //              nb_task = 0 ;
31                 nb_dep_total = 0 ;
32         }
33         
34         
35         /**
36          * Return the amount of tasks in the graph.
37          * @return The amount of tasks
38          */
39         public int getNbGTask()
40         {
41                 return graph.size() ;
42 //              return nb_task ;
43         }
44         
45         
46         /**
47          * Add a task into the graph.
48          * @param t Task to be add
49          */
50         public void addGTask( GTask _t )
51         {
52                 if( _t != null )
53                 {
54                         graph.add( _t.getNum(), _t ) ;
55                         nb_dep_total += _t.getNbDep() ;
56 //                      nb_task ++ ;
57                 }
58         }
59         
60         
61         /**
62          * Add a list of tasks into the graph.
63          * @param _lt : Tasks list to be added
64          */
65         public void addGTasks( ArrayList<GTask> _lt )
66         {
67                 if( _lt != null )
68                 {
69                         for( int i = 0 ; i < _lt.size() ; i++ )
70                         {
71                                 graph.add( _lt.get( i ).getNum(), _lt.get( i ) ) ;
72                                 nb_dep_total += _lt.get( i ).getNbDep() ;
73 //                              nb_task ++ ;
74                         }
75                 }
76         }
77         
78         
79         /**
80          * Return the graph in a tasks list form.
81          * @return The tasks list
82          */
83         public ArrayList<GTask> getGraph()
84         {
85                 return graph ;
86         }
87         
88         
89         /**
90          * Return the average of dependencies of tasks in the graph.
91          * @return The average of dependencies
92          */
93         public double getAverageDep()
94         {
95                 return nb_dep_total / graph.size() ;
96         }
97
98
99         /**
100          * Print the graph in a comprehensible text version.
101          */
102         public void print() 
103         {
104                 System.out.println();
105                 System.out.println( "\t=> Composition of interaction graph:\n" ) ; 
106                 for( int i = 0 ; i < graph.size() ; i++ )
107                 {
108                         System.out.println( "\t\tTask \""+ graph.get(i).getNum() +"\" => " + graph.get(i).printDep() ) ;
109                 }
110                 
111                 System.out.println();
112         }
113 }
114
115 /** La programmation est un art, respectons ceux qui la pratiquent !! **/