Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adding new functionalities.
[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_dep_total ;
21         private int maxDep ;
22         
23         
24         /**
25          * Default constructor.
26          */
27         public Graph()
28         {
29                 graph = new ArrayList<GTask>() ;
30                 nb_dep_total = 0 ;
31                 maxDep = 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         }
43         
44         
45         /**
46          * Add a task into the graph.
47          * @param _t Task to be add
48          */
49         public void addGTask( GTask _t )
50         {
51                 if( _t != null )
52                 {
53                         graph.add( _t.getNum(), _t ) ;
54                         nb_dep_total += _t.getNbDep() ;
55                         
56                         if ( _t.getNbDep() > maxDep )
57                         {
58                                 maxDep = _t.getNbDep() ;
59                         }
60                 }
61         }
62         
63         
64         /**
65          * Add a list of tasks into the graph.
66          * @param _lt : Tasks list to be added
67          */
68         public void addGTasks( ArrayList<GTask> _lt )
69         {
70                 if( _lt != null )
71                 {
72                         for( int i = 0 ; i < _lt.size() ; i++ )
73                         {
74                                 graph.add( _lt.get( i ).getNum(), _lt.get( i ) ) ;
75                                 nb_dep_total += _lt.get( i ).getNbDep() ;
76                                 
77                                 if ( _lt.get( i ).getNbDep() > maxDep )
78                                 {
79                                         maxDep = _lt.get( i ).getNbDep() ;
80                                 }
81                         }
82                 }
83         }
84         
85         
86         /**
87          * Return the graph in a tasks list form.
88          * @return The tasks list
89          */
90         public ArrayList<GTask> getGraph()
91         {
92                 return graph ;
93         }
94         
95         
96         /**
97          * Return the average of dependencies of tasks in the graph.
98          * @return The average of dependencies
99          */
100         public double getAverageDep()
101         {
102                 return nb_dep_total / graph.size() ;
103         }
104         
105         
106         /**
107          * Return the max amount of dependencies a task of the graphs can have.
108          * @return The maximum amount of dependencies
109          */
110         public int getMaxDep()
111         {
112                 return maxDep ;
113         }
114
115
116         /**
117          * Print the graph in a comprehensible text version.
118          */
119         public void print() 
120         {
121                 System.out.println();
122                 System.out.println( "\t=> Composition of interaction graph:\n" ) ; 
123                 for( int i = 0 ; i < graph.size() ; i++ )
124                 {
125                         System.out.println( "\t\tTask \""+ graph.get(i).getNum() +"\" => " + graph.get(i).printDep() ) ;
126                 }
127                 
128                 System.out.println();
129         }
130 }
131
132 /** La programmation est un art, respectons ceux qui la pratiquent !! **/