Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
58a719da76bbe3f1a79b852e42b2f756bd2d7194
[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 interaction graph of an application
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 nb_task ;
42         }
43         
44         
45         /**
46          * Add a task in the interaction 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                         nb_task ++ ;
56                 }
57         }
58         
59         
60         /**
61          * Return the graph in a tasks list form.
62          * @return The tasks list
63          */
64         public ArrayList<GTask> getGraph()
65         {
66                 return graph ;
67         }
68         
69         
70         /**
71          * Return the average of dependencies of tasks in the graph.
72          * @return The average of dependencies
73          */
74         public double getAverageDep()
75         {
76                 return nb_dep_total / nb_task ;
77         }
78
79
80         /**
81          * Print the graph in a text version.
82          */
83         public void print() 
84         {
85                 System.out.println();
86                 System.out.println( "\t=> Composition of interaction graph:\n" ) ; 
87                 for( int i = 0 ; i < nb_task ; i++ )
88                 {
89                         System.out.println( "\t\tTask \""+ graph.get(i).getNum() +"\" => " + graph.get(i).printDep() ) ;
90                 }
91                 
92                 System.out.println();
93         }
94 }
95
96 /** La programmation est un art, respectons ceux qui la pratiquent !! **/