Sunday 15 April 2012

java - Finding all possible Combination of Pairs in a list -


I am using parts with the implementation of integration and try to remove all possible u and DV pairs are added to a list of all things, the code provided is my method, except that the function objects have been replaced with strings for readability so that people Can remove it from context.

  ArrayList & lt; String & gt; FuncObjects = giveList (CALC.MULTIPLY, function); // Any way you like it // All combinations are stored in matrix int pair = 0; String [] [] udvPairs = new string [funcObjects.size () * funcObjects.size ()] [2]; // for (int skip = 0; skip & lt; 1; skip ++) {// has been commented for a better solution (int i = 0; i & lt; funcObjects.size () - 1 ; I ++) {system. Out.println ("i =" + i); //System.out.println (function.size ()); For (int j = 0; j & lt; funcObjects.size () - i; j ++) {System.out.println ("j =" + j); Calc Object U = "1"; Calcobject dv = "1"; (Int start = j; start & lieutent; = j + i; start ++) {// This loop is here that is creating my u / Note that it goes in sequence and therefore there is no // account for those items which are not next to each other in the list / My question is this U = U + "+" + + + funcObjects.get ( Start); } (Int end = 0; end & lt; j; end ++) {dv = dv + "*" + funcObjects.get (end); } For (intend = J + I + 1; and end lie; the sync box;); and ++) {dv = dv + "*" + funcObjects.get (end); } System.out.println ("Pair" + Jopter Quikter + "; U:" + u.toString (+) + "dv:" + dv.toString ()); UdvPairs [Duo Control] [0] = U; UdvPairs [Duo Control] [1] = Dv; PairCounter ++; }}   

This is my code so far. The combinations given by me are correct, but it does not give me all the combinations, for example:

x * SIN (x) * COS (x)

ie. ["x", "SIN (x)", "cos"]

me

  i = 0 j = 0 Pair 0; U: X DV: SIN (X) * COS (X) J = 1 pair 1; U: SIN (X) DV: X * COS (X) J = 2 pair 2; U: COS (X) DV: X * SIN (X) I = 1J = 0 pair3; U: X * SIN (X) DV: COS (X) J = 1 pair 4; U: SIN (x) * cos (x) dv: x   

to leave it: x * COS (x) DV: SIN (x)

So my question is, does anyone know how to create an account for the combination in which the parts are not next to each other? The program is not throwing any errors, I do not know what I need to implement.

Thank you.

This is the code to work on:

  array list & Lt; String []> UdvPairs = new ArrayList & lt; & Gt; (); String [] temp = new string [2]; String not = "1"; For (int i = 0; i & lt; funcObjects.size (); i ++) {notOne = notOne + = funcObjects.get (i); } Temp [0] = "1"; Temporary [1] = non; UdvPairs.add (temporary); Temp = new string [2]; Temporary [1] = "1"; Temporary [0] = non; UdvPairs.add (temporary); For (int i = 0; i & lt; funcObjects.size () - 1; i ++) {//System.out.println("i= "+ i); //System.out.println (function.size ()); For (int j = 0; j & lt; funcObjects.size () - i; j ++) {//System.out.println("j= "+ j); For (int quit = 0; Skip & lt; funcObjects.size () - i - j; skip ++) {//System.out.println("skip= "+ skip); String u = "1"; String dv = "1"; U + = funcObjects.get (j); For (Int start = J + skip + 1; Start & lt; = j + i + skip; start ++) {u + = ufuncObjects.get (start); } (Int end = 0; end  ​​   

No comments:

Post a Comment