Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adding new functionalities.
[mapping.git] / src / and / Mapping / Graph.java
index 58a719d..e9ac2a2 100644 (file)
@@ -8,7 +8,7 @@ import java.util.ArrayList;
 
 
 /**
- * Class representing the interaction graph of an application
+ * Class representing the application's graph
  * @author Sébastien Miquée
  */
 public class Graph implements Serializable
@@ -17,8 +17,8 @@ public class Graph implements Serializable
 
        
        private ArrayList<GTask> graph ;
-       private int nb_task ;
        private int nb_dep_total ;
+       private int maxDep ;
        
        
        /**
@@ -27,8 +27,8 @@ public class Graph implements Serializable
        public Graph()
        {
                graph = new ArrayList<GTask>() ;
-               nb_task = 0 ;
                nb_dep_total = 0 ;
+               maxDep = 0 ;
        }
        
        
@@ -38,21 +38,47 @@ public class Graph implements Serializable
         */
        public int getNbGTask()
        {
-               return nb_task ;
+               return graph.size() ;
        }
        
        
        /**
-        * Add a task in the interaction graph.
-        * @param t Task to be add
+        * Add a task into the graph.
+        * @param _t Task to be add
         */
-       public void addGTask( GTask t )
+       public void addGTask( GTask _t )
        {
-               if( t != null )
+               if( _t != null )
                {
-                       graph.add( t.getNum(), t ) ;
-                       nb_dep_total += t.getNbDep() ;
-                       nb_task ++ ;
+                       graph.add( _t.getNum(), _t ) ;
+                       nb_dep_total += _t.getNbDep() ;
+                       
+                       if ( _t.getNbDep() > maxDep )
+                       {
+                               maxDep = _t.getNbDep() ;
+                       }
+               }
+       }
+       
+       
+       /**
+        * Add a list of tasks into the graph.
+        * @param _lt : Tasks list to be added
+        */
+       public void addGTasks( ArrayList<GTask> _lt )
+       {
+               if( _lt != null )
+               {
+                       for( int i = 0 ; i < _lt.size() ; i++ )
+                       {
+                               graph.add( _lt.get( i ).getNum(), _lt.get( i ) ) ;
+                               nb_dep_total += _lt.get( i ).getNbDep() ;
+                               
+                               if ( _lt.get( i ).getNbDep() > maxDep )
+                               {
+                                       maxDep = _lt.get( i ).getNbDep() ;
+                               }
+                       }
                }
        }
        
@@ -73,18 +99,28 @@ public class Graph implements Serializable
         */
        public double getAverageDep()
        {
-               return nb_dep_total / nb_task ;
+               return nb_dep_total / graph.size() ;
+       }
+       
+       
+       /**
+        * Return the max amount of dependencies a task of the graphs can have.
+        * @return The maximum amount of dependencies
+        */
+       public int getMaxDep()
+       {
+               return maxDep ;
        }
 
 
        /**
-        * Print the graph in a text version.
+        * Print the graph in a comprehensible text version.
         */
        public void print() 
        {
                System.out.println();
                System.out.println( "\t=> Composition of interaction graph:\n" ) ; 
-               for( int i = 0 ; i < nb_task ; i++ )
+               for( int i = 0 ; i < graph.size() ; i++ )
                {
                        System.out.println( "\t\tTask \""+ graph.get(i).getNum() +"\" => " + graph.get(i).printDep() ) ;
                }