Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8f255cd518959d83669805cd4206f5ea5dc89e37
[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         
22         
23         /**
24          * Default constructor.
25          */
26         public Graph()
27         {
28                 graph = new ArrayList<GTask>() ;
29                 nb_dep_total = 0 ;
30         }
31         
32         
33         /**
34          * Return the amount of tasks in the graph.
35          * @return The amount of tasks
36          */
37         public int getNbGTask()
38         {
39                 return graph.size() ;
40         }
41         
42         
43         /**
44          * Add a task into the graph.
45          * @param _t Task to be add
46          */
47         public void addGTask( GTask _t )
48         {
49                 if( _t != null )
50                 {
51                         graph.add( _t.getNum(), _t ) ;
52                         nb_dep_total += _t.getNbDep() ;
53 //                      nb_task ++ ;
54                 }
55         }
56         
57         
58         /**
59          * Add a list of tasks into the graph.
60          * @param _lt : Tasks list to be added
61          */
62         public void addGTasks( ArrayList<GTask> _lt )
63         {
64                 if( _lt != null )
65                 {
66                         for( int i = 0 ; i < _lt.size() ; i++ )
67                         {
68                                 graph.add( _lt.get( i ).getNum(), _lt.get( i ) ) ;
69                                 nb_dep_total += _lt.get( i ).getNbDep() ;
70                         }
71                 }
72         }
73         
74         
75         /**
76          * Return the graph in a tasks list form.
77          * @return The tasks list
78          */
79         public ArrayList<GTask> getGraph()
80         {
81                 return graph ;
82         }
83         
84         
85         /**
86          * Return the average of dependencies of tasks in the graph.
87          * @return The average of dependencies
88          */
89         public double getAverageDep()
90         {
91                 return nb_dep_total / graph.size() ;
92         }
93
94
95         /**
96          * Print the graph in a comprehensible text version.
97          */
98         public void print() 
99         {
100                 System.out.println();
101                 System.out.println( "\t=> Composition of interaction graph:\n" ) ; 
102                 for( int i = 0 ; i < graph.size() ; i++ )
103                 {
104                         System.out.println( "\t\tTask \""+ graph.get(i).getNum() +"\" => " + graph.get(i).printDep() ) ;
105                 }
106                 
107                 System.out.println();
108         }
109 }
110
111 /** La programmation est un art, respectons ceux qui la pratiquent !! **/