Java et Mascopt Jean-François Lalande, Michel Syska, Yann Verhoeven Projet Mascotte, IS-INRIA Sophia-Antipolis, France Formation Mascotte 09 janvier 00
Java Java et Mascopt - Formation Mascotte 09 janvier 00
Java - Compiler et Exécuter > ls Lancement.java Tutoriel.java > javac Tutoriel.java > javac Lancement.java > ls Lancement.class Lancement.java Tutoriel.class Tutoriel.java > export CLASSPATH=./:$CLASSPATH > java Lancement Nombre de vertex: 0 > cd /net/ailleurs/pas ici/a l autre bout du monde > java Lancement Nombre de vertex: 0 Java et Mascopt - Formation Mascotte 09 janvier 00
class Tutoriel Notion de Classe public int nb vertex = 0; private int nb tutoriel = 0; public void displaynbvertex() System.out.println( Nombre de vertex: + nb vertex); 8 9 0 Java et Mascopt - Formation Mascotte 09 janvier 00
public class Lancement public static void main(string args []) Tutoriel tutoriel = new Tutoriel(); tutoriel.displaynbvertex(); 8 9 0 Java et Mascopt - Formation Mascotte 09 janvier 00
package tutoriel.essai; public class Tutoriel public int nb vertex = 0; private int nb tutoriel = 0; Packages public void displaynbvertex() System.out.println( Nombre de vertex: + nb vertex); 8 9 0 ls tutoriel/essai Tutoriel.java Tutoriel.class Java et Mascopt - Formation Mascotte 09 janvier 00
//import tutoriel.essai. ; import tutoriel.essai.tutoriel; public class Lancement public static void main(string args []) Tutoriel tutoriel = new Tutoriel(); tutoriel.displaynbvertex(); 8 9 0 Java et Mascopt - Formation Mascotte 09 janvier 00
package tutoriel.essai; Constructeur public class Tutoriel public int nb vertex = 0; private int nb tutoriel = 0; public Tutoriel() System.out.println( Je me construits... ); public void displaynbvertex() System.out.println( Nombre de vertex: + nb vertex); 8 9 0 Java et Mascopt - Formation Mascotte 09 janvier 00
if (condition) else while (condition) Structures de controle for(int i=0; i<; i++) System.out.println( i= +i); switch(k) case : System.out.println( Case k= ); break; case : System.out.println( Case k= ); break; default: System.out.println( case default ); Java et Mascopt - Formation Mascotte 09 janvier 00 8
Vector, List, ArrayList Set, HashSet, HashTable Iterateur sur des ensembles Vector v = new Vector(); v.add(new Integer(9)); v.add(new Integer()); Iterator it = v.iterator(); while (v.hasnext()) Integer courant = (Integer)v.next(); System.out.println( courant= + courant); 8 9 0 Java et Mascopt - Formation Mascotte 09 janvier 00 9
Mascopt Java et Mascopt - Formation Mascotte 09 janvier 00 0
Récuperer Mascopt Mascopt par CVS export CVSROOT=cvs sop.inria.fr:/cvs/mascotte export CVS RSH=ssh cvs checkout mascoptdev cd mascoptdev export CVS RSH=ssh cvs d :ext:login@cvs sop.inria.fr:/cvs/mascotte checkout mascoptdev cd mascoptdev Architecture bin which contains scripts which launch applications docs wich contains the documentation files which contains some files of graphs or networks jar which contains the jar files launch which contains the code of applications licences all the licences of each part of provided code Java et Mascopt - Formation Mascotte 09 janvier 00
src which contains the source code of algorithms developed by users. This is the place where you can put the code of your algorithm. samples which contains some samples references of classes of mascopt. tests wich contains bad code of developers, where they test their algorithms Ou aller? toutes les algorithmes (classes) sans main() src/ tous les tests qui utilisent ces algos tests/ quand l algo marche écrire un main() dans samples/ Java et Mascopt - Formation Mascotte 09 janvier 00
mascoptlib Division du code en deux parties mascoptlib gestion des graphes, GUI gestion des entrées sorties algorithmes validés et robustes mascoptdev Espace utilisateurs Tests, algorithmes en développement dans mascoptdev on trouve mascoptlib.jar Java et Mascopt - Formation Mascotte 09 janvier 00
Makefile source SETENV make Compile les classes des utilisateurs (src/...) Compile les mains des utilisateurs (tests/...) Compile les exemples des utilisateurs (samples/...) make javadoc Construit la javadoc de mascoptdev et mascoptlib popotte: /unison/mascopt/mascoptdev> source SETENV popotte: /unison/mascopt/mascoptdev> make make s all log Cplex detected. popotte: /unison/mascopt/mascoptdev>ls classes/... Java et Mascopt - Formation Mascotte 09 janvier 00
Java et Mascopt - Formation Mascotte 09 janvier 00
Vertex n0 = new Vertex(); Vertex n = new Vertex(); Vertex n = new Vertex(); Vertex n = new Vertex(); Vertex n = new Vertex(); Vertex n = new Vertex(); Créér un graphe // creation des arcs entre les neouds Arc a0 = new Arc(n0, n); Arc a = new Arc(n, n); Arc a = new Arc(n, n); Arc a = new Arc(n, n); Arc a = new Arc(n, n); // creation d un ensemble de noeuds V VertexSet V = new VertexSet(); // on ajoue les noeuds ds l ensemble de noeuds V.add(n0); 8 9 0 8 9 Java et Mascopt - Formation Mascotte 09 janvier 00
V.add(n); V.add(n); V.add(n); V.add(n); V.add(n); // creation d un ensemble d arc E ArcSet E = new ArcSet(V); E.add(a0); E.add(a); E.add(a); E.add(a); E.add(a); // cration d un Digraph graph=v,e DiGraph graph = new DiGraph(V, E); // on l affiche sur la sortie standart System.out.println( mon graph = + graph); 0 8 9 0 8 Java et Mascopt - Formation Mascotte 09 janvier 00
Storing/Getting values For storing a String on vertix, arc, node set, edge set, graph: getvalue(string name) setvalue(string name, String value) For storing an Integer on nodes, arcs and graphs: getintegervalue(string name) setintegervalue(string name, Integer value) For storing an int on nodes, arcs and graphs: getintvalue(string name) setintvalue(string name, int value) For storing a Double on nodes, arcs and graphs: getdoublevalue(string name) setdoublevalue(string name, Double value) For storing a double on nodes, arcs and graphs: getdouvalue(string name) setdouvalue(string name, double value) Java et Mascopt - Formation Mascotte 09 janvier 00 8
Exemple: v.setvalue( poids, ); v.getvalue( poids ); v.setintegervalue( poids, new Integer(9)); v.setdouvalue( poids, 8.); Conversions: String s a = ; String s b =. ; String s c =. ; String s d = ; Integer a = new Integer(Integer.parseInt(s a)); double b = Double.parseFloat(s b); Double c = new Double(Double.parseFloat(s c)); int d = Integer.parseInt(s d); 8 Java et Mascopt - Formation Mascotte 09 janvier 00 9
Ensemble et sous-ensemble Remplir un set NodeSet V0 = new NodeSet(); for (int i=0; i<0;i++) V0.add(new Node(Math.random(),Math.random())); System.out.println( V0: + V0); Créér un subset NodeSet V = new NodeSet(V0); System.out.println( V: + V); Synchronisation des subset par rapport au super set Java et Mascopt - Formation Mascotte 09 janvier 00 0
Chemins Construction d un chemin DiGraph g =...; Path p = new Path(g.getEdgeSet()); Arc e =...; Arc e =...; Arc e =...; p.concat(e); p.concat(e); p.concat(e); Parcourir un chemin Vertex current = p.getstart(); while (current!= p.getend()) System.out.println( Current node: + current); 8 9 Java et Mascopt - Formation Mascotte 09 janvier 00
Arc e = p.nextarc(current); System.out.println( Current edge: + e); current = p.nextvertex(current); 8 9 Multi-path Path p =...; Path p =...; boolean ok = p.merge(p); Java et Mascopt - Formation Mascotte 09 janvier 00
Entrées/Sorties try // creation du writer MGLWriter writer = new MGLWriter(args[0]); // on ajoute ce qu on veut ecrire (ici le graph) writer.add(graph); // on pourrai rajouter d autres objets... // on ecrit writer.write(); catch (java.io.filenotfoundexception fe) fe.printstacktrace(); // le tout dans un bloc try catch pq ca peut lancer des exceptions. 8 9 0 Java et Mascopt - Formation Mascotte 09 janvier 00
// on cree le reader. MGLReader mglr = new MGLReader(args[0]); try mglr.parse(); catch (Exception e) System.out.println( Error when parsing file! ); // on recupere un iterateur sur les graphs du fichier Iterator itg = mglr.getabstractgraphs(); while (itg.hasnext()) System.out.println( Graph read = + itg.next()); 8 9 0 Java et Mascopt - Formation Mascotte 09 janvier 00
GraphChooser gc = new GraphChooser(); HashMap my graphs = null; if (args.length < ) my graphs = gc.getgraphhashmapgml(); else my graphs = gc.getgraphhashmapgml(args[0]); DiGraph G = (DiGraph) my graphs.get( graph Cable ); DiGraph R = (DiGraph) my graphs.get( graph Request ); 8 9 0 Java et Mascopt - Formation Mascotte 09 janvier 00
Network files fichier MGL contenant: Graphe nommé graph Request Graphe nommé graph Cable Ces deux graphes partagent l ensemble de nœuds Cette convention risque de changer... Java et Mascopt - Formation Mascotte 09 janvier 00
The God format c Reseau de test: cables c n e 0 e 0 e e 0 c Reseau de test: requetes c r 0 8 r 0 r 0 9 test.graph test.od Java et Mascopt - Formation Mascotte 09 janvier 00
Conversion en mgl odmgl programme dans mascoptdev/bin utilisation: java OdMglLauncher usage: odmgl filein.graph filein.od fileout.mgl [ h] [ help] Try odmgl help for more options. Java et Mascopt - Formation Mascotte 09 janvier 00 8