4 import java.io.Serializable;
5 import java.util.ArrayList;
11 * Class representing the application's graph
12 * @author Sébastien Miquée
14 public class Graph implements Serializable
16 private static final long serialVersionUID = 1L;
19 private ArrayList<GTask> graph ;
20 private int nb_dep_total ;
25 * Default constructor.
29 graph = new ArrayList<GTask>() ;
36 * Return the amount of tasks in the graph.
37 * @return The amount of tasks
39 public int getNbGTask()
46 * Add a task into the graph.
47 * @param _t Task to be add
49 public void addGTask( GTask _t )
53 graph.add( _t.getNum(), _t ) ;
54 nb_dep_total += _t.getNbDep() ;
56 if ( _t.getNbDep() > maxDep )
58 maxDep = _t.getNbDep() ;
65 * Add a list of tasks into the graph.
66 * @param _lt : Tasks list to be added
68 public void addGTasks( ArrayList<GTask> _lt )
72 for( int i = 0 ; i < _lt.size() ; i++ )
74 graph.add( _lt.get( i ).getNum(), _lt.get( i ) ) ;
75 nb_dep_total += _lt.get( i ).getNbDep() ;
77 if ( _lt.get( i ).getNbDep() > maxDep )
79 maxDep = _lt.get( i ).getNbDep() ;
87 * Return the graph in a tasks list form.
88 * @return The tasks list
90 public ArrayList<GTask> getGraph()
97 * Return the average of dependencies of tasks in the graph.
98 * @return The average of dependencies
100 public double getAverageDep()
102 return nb_dep_total / graph.size() ;
107 * Return the max amount of dependencies a task of the graphs can have.
108 * @return The maximum amount of dependencies
110 public int getMaxDep()
117 * Print the graph in a comprehensible text version.
121 System.out.println();
122 System.out.println( "\t=> Composition of interaction graph:\n" ) ;
123 for( int i = 0 ; i < graph.size() ; i++ )
125 System.out.println( "\t\tTask \""+ graph.get(i).getNum() +"\" => " + graph.get(i).printDep() ) ;
128 System.out.println();
132 /** La programmation est un art, respectons ceux qui la pratiquent !! **/