Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implementation of new functions.
authorSébastien Miquée <sebastien.miquee@univ-fcomte.fr>
Fri, 5 Mar 2010 06:46:21 +0000 (07:46 +0100)
committerSébastien Miquée <sebastien.miquee@univ-fcomte.fr>
Fri, 5 Mar 2010 06:46:21 +0000 (07:46 +0100)
- Adding some functions in Cluster in order to compute new indicators
  for a novel mapping algorithm.

- Adding new functions in Utils to read and write Mapping objects in
  a file.

- Returning to the real relative standard deviation for heterogeneity
  degree computation in Grid.

src/and/Mapping/Cluster.java
src/and/Mapping/Grid.java
src/and/Mapping/Utils.java

index 39c48bd..4d59d3d 100644 (file)
@@ -274,6 +274,38 @@ public class Cluster implements Serializable
        {
                return freenodes.size() ;
        }
+       
+       
+       /**
+        * Compute and return the real available computing power of the cluster,
+        * including the heterogeneity degree of the platform. 
+        * @param _het The heterogeneity degree of the platform
+        * @return The real available computing power
+        */
+       public double getAvailablePower( double _het )
+       {
+               double ret = 0 ;
+               
+               /** If there is some available nodes **/
+               if( freenodes.size() > 0 )
+               {
+                       double het = _het ;
+                       double totalPower = 0 ;
+                       
+                       if( het == 0 )
+                               het = 0.00001 ;
+                       
+                       for( int i = 0 ; i < freenodes.size() ; i++ )
+                       {
+                               totalPower += freenodes.get( i ).getPower() ;
+                       }
+                       
+                       ret = Math.pow( ( totalPower / freenodes.size() ), ( 2 * het) ) *
+                             ( freenodes.size() / ( het * het) ) ;
+               }
+               
+               return ret ;
+       }
 
 
        /**
index d93b65e..3501a2d 100644 (file)
@@ -401,10 +401,8 @@ public class Grid implements Serializable
                temp = temp / gnodesList.size() ;
                std = Math.sqrt( temp ) ;
                
-               /** Computation of the relative standard deviation
-                * plus modifications 
-                */
-               hd = 100 * std / average / 10 ;
+               /** Computation of the relative standard deviation **/
+               hd = 100 * std / average ;
                
                
                return hd ;
index ff2393a..a5ec4d2 100644 (file)
@@ -279,6 +279,57 @@ public class Utils
        }
        
        
+       /**
+        * Write a mapping done in a file.
+        * @param _mp The mapping done to be write
+        * @param _path File's path
+        * @param _file File's name
+        */
+       public static void writeMapping( Mapping _mp, String _path, String _file )
+       {
+               if( _file.equals( "" ) )
+               {
+                       System.err.println( "No file's name !\n" ) ;
+                       return ;
+               }
+               
+               if ( ! _file.endsWith( ".xml" ) )
+               {
+                       _file = _file + ".xml"; // On ajoute l'extension xml au nom du fichier
+               }
+               
+               if( ! _file.equals( "" ) )
+               {
+                       String path = "" ;
+                       
+                       if( _path.length() != 0 )
+                       {
+                               path = _path+"/"+_file ;
+                       } else {
+                               path = new String( "./" + _file ) ;
+                       }
+                       
+                       XStream xstream = new XStream( new DomDriver() ) ;
+                       
+                       String xml = xstream.toXML( _mp ) ;
+                       
+                       PrintWriter ecrivain = null ;
+
+                       try {
+                               ecrivain = new PrintWriter( new OutputStreamWriter( new FileOutputStream( path ), "UTF8" ) ) ;
+
+                               ecrivain.println( "<?xml version=\"1.0\" encoding=\"UTF8\"?>" ) ;
+                               ecrivain.println( xml ) ;
+
+                               ecrivain.close() ;
+                       } catch( Exception e ) {
+                               System.err.println( "\nError during the write opération !\n" ) ;
+                               e.printStackTrace() ;
+                       }
+               }
+       }
+       
+       
        /**
         * Read an application Graph from a file.
         * @param _file File's name
@@ -374,6 +425,54 @@ public class Utils
                return gr ;
        }
        
+       
+       /**
+        * Read a Mapping done from a file.
+        * @param _file File's name
+        * @param _path File's path
+        * @return The Mapping read
+        */
+       public static Mapping readMapping( String _path, String _file )
+       {       
+               if ( _file.equals( "" ) )
+               {
+                       System.err.println( "No file's name !\n" ) ;
+                       return null ;
+               }       
+               
+               if ( ! _file.endsWith( ".xml" ) )
+               {
+                       _file = _file + ".xml"; // On ajoute l'extension xml au nom du fichier
+               }
+
+               String path = "" ;
+               
+               if( _path.length() != 0 )
+               {
+                       path = _path+"/"+_file ;
+               } else {
+                       path = new String( "./" + _file ) ;
+               }       
+               
+               Mapping mp = null ;
+               
+               XStream xstream = new XStream( new DomDriver() ) ;
+               
+               try {
+                       mp = (Mapping) xstream.fromXML( new FileInputStream( path ) ) ;
+               } catch( FileNotFoundException e ) {
+                       System.err.println( "File not found !\n" ) ;
+                       e.printStackTrace();
+                       return null ;
+               } catch( ClassCastException e ) {
+                       System.err.println( "The file does not contain a valid Grid" ) ;
+                       e.printStackTrace() ;
+                       return null ;
+               }
+               
+               return mp ;
+       }
+       
 }