Pick all subgraphs by a specific pattern from a graph -


so i'm looking forward pick lets triangle/square/../hexagon graph.

what mean that:

input keybord: a-b b-c c-a 

and

output m-n-o, x-y-z, s-t-u
(where each of subgraphs respect relation ship pattern of vertex)

how solve this: has raw version not optimisations or other stuff, without backtracking / recursion.

solution: transpose vertexes matrix , combinations in loops.

the problem have: instance if want graph accept octogns, need make 8 in for's ?!

own solution not best, suficient acomplish fallowing. acomplished combinatorics jar. hole helps

    @suppresswarnings("unchecked")     public static void drawmatrix(graph g, int tempmatrixsize){         system.out.println(" ");         system.out.println("matrix:");         arraylist<node> nodesset = new arraylist<>();         nodesset = (arraylist<node>) g.getnodes().clone();          int size = nodesset.size();          int[][] matrix = new int[size][size];          system.out.print("  ");         (node node : nodesset){             system.out.print(" " + node.getname()+ " ");         }         system.out.println();           (int i=0; i<size; i++) {             system.out.print(nodesset.get(i).getname()+ " ");             (int j=0; j<size; j++){                 if (i == j) {                     system.out.print(" 1 ");                     matrix[i][j] = 1;                  }                 else{                     if (nodesset.get(i).isfriend(nodesset.get(j))) {                         system.out.print(" x ");                         matrix[i][j] = 1;                     }                     else {                         system.out.print(" 0 ");                         matrix[i][j] = 0;                     }                 }             }             system.out.println();         }         system.out.println();          // temp matrix         int[][] tempmatrix = new int[tempmatrixsize][tempmatrixsize];          // find combinations         arraylist<integer> al= new arraylist<>();         (int = 0; i<size; i++ ){             al.add(i);         }          icombinatoricsvector<integer> initialvector = factory.createvector(al);         generator<integer> gen = factory.createsimplecombinationgenerator(initialvector, tempmatrixsize);         int index = 0;         (icombinatoricsvector<integer> combination : gen) {             boolean isconnected = true;             system.out.println(combination);             list<integer> comb = combination.getvector();             for(int i=0; i<tempmatrixsize; i++){                 for(int j=0; j<tempmatrixsize; j++){                     tempmatrix[i][j] = matrix[comb.get(i)][comb.get(j)]; //                  system.out.print(tempmatrix[i][j]+ " ");                 }                 system.out.println();               }             // main matrix coordinations             system.out.println("main matrix used coords: ");             for(int i=0; i<tempmatrixsize; i++){                 for(int j=0; j<tempmatrixsize; j++){                     tempmatrix[i][j] = matrix[comb.get(i)][comb.get(j)];                     system.out.print("["+comb.get(i)+","+comb.get(j)+"] ");                 }                 system.out.println();             }             system.out.println();              for(int i=0; i<tempmatrixsize; i++){                 for(int j=0; j<tempmatrixsize; j++){                     if (tempmatrix[i][j] == 0){                         isconnected = false;                     }                 }             }             if (isconnected) {                 system.out.println("is connected >" + tempmatrixsize);                 (int i=0; i<tempmatrixsize; i++) {                     system.out.println(" >" +nodesset.get(comb.get(i)).getname());                 }                        }         } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -