package chocobar.combi; import java.util.*; // listes import exception.*; public class EdgeMatrixModel implements EdgeModel { private int cardV; private boolean[][] adjacent; /** * Default constructor **/ public EdgeMatrixModel() { this(10); this.cardV=0; } /** * Constructor with card (number of vertices) as a parameter **/ public EdgeMatrixModel(int card) { this.cardV=card; this.adjacent=new boolean[this.cardV][this.cardV]; } /** * Fonction qui renvoie la dimension de cette matrice d'adjance **/ public int getCardV(){ return this.cardV; } /** Fonction qui réinitialise à la taille donnée. */ public int setSize(int size) { cardV=size; adjacent=new boolean[size][size]; return size; } /** * Fonction qui rajoute un arc partant du sommet srcV * vers sommet dstV **/ public void addEdge(int srcV,int dstV) throws OutOfRangeVerticeException // plustard qu'on parse un graphe et rajoute des arcs sans // passer par l'initialisation, il faut detecter le cas qu'on // rajoute un arc n'importe quoi { if ((srcV<0) ||(dstV<0) ||(srcV>=cardV) || (dstV>=cardV)) { throw new OutOfRangeVerticeException(); } adjacent[srcV][dstV]=true; } /** * Fonction qui verifie l'existence d'un arc du sommet srcV * vers sommet dstV **/ public boolean isEdge(int srcV,int dstV){ return adjacent[srcV][dstV]; } /** * Fonction qui verifie si les sommets adjacents a src sont * uniquement les sommets contenus dans le tableau dst * Si non alors elle renvoie -1 et si oui elle renvoie le premier * sommet dst adjacent a src **/ public int withOnlyEdges(int src, Vector dst){ Collection srcAdj = getAdjacent(src); int taille = srcAdj.size(); int adj=-1; Object[] adjacents=srcAdj.toArray(); if (taille>dst.size()){ //y a des sommets qui ne sont pas dans le tableau return -1; } else { for (int i=0; i cardV < 3/4 * adj.length if ((4*this.cardV) > (3*this.adjacent.length)){ int nuvolen=this.adjacent.length * 2; boolean[][] copie = new boolean[nuvolen][nuvolen]; for (int i=0; i=this.cardV)){ throw new OutOfRangeVerticeException(); } // create a new array (cardV-1) * (cardV-1) boolean[][] neoAdj= new boolean[this.cardV-1][this.cardV-1]; // fill the new array zith the values of the previous // adjacency matrix int ni=0; int nj=0; for (int i=0;irmIdx){ni=i-1; } if (jrmIdx){nj=j-1; } neoAdj[ni][nj]=this.adjacent[i][j]; } } } // associate the new adjacency matrix to the class this.cardV=this.cardV-1; this.adjacent=neoAdj; } }