Results 1 to 8 of 8
 03152010, 05:18 PM #1Member
 Join Date
 Dec 2009
 Posts
 59
 Rep Power
 0
finding possible ordering set of vector
hello
I want to do some reordering of elements in a vector (vect_temp) according to criteria:
after finding the first element I need to find the next element after calling functions
Min_diff(vect_temp);
nex_minr(vect_temp,next_point);
the first function will generate the vector (vect_diff) of possible elements and also the second function will find vector ( vect_min) of elements
if element in the (vect_diff) is equal to the element in ( vect_min) then add this element into the ordered set with this equal element and continue ordering of complete vector vect(temp)
the problem is sometimes that many elements in vect_diff sometimes equal elements in vect_min so that I want to generate all possible ordering
I did the code that finds first equal element and continue ordering but the prolem is that I have sometimes muliple equal elements I don't know how to generate the solutions for the other multiple element
[code]
for (int y=0; y< vector_temp.size(); y++){
Min_diff(vect_temp);
nex_minr(vect_temp,next_point);
for (int i=0; i< vect_diff.size(); i++){
String element_min= vect_diff.get(i).toString();
if( vect_min.contains(element_min)){
vec_ordering.add(element_min);
_2nd_min_element= element_min;
vec_temp.removeElement(next_point);
next_point=_2nd_min_element;
i= vect_diff.size();
}// end if condition
} // end for (i)loop
}// end for (y) loop
[\code]
as I said before I don't have problem in finding first element or next element I just want to find all possible ordering set because at each time there is multiple element in vec_diff equal to multiple elements in vec_min I want to find all solutions for example first solution with first element in vec_diff equal to element in vec_min and second solution with second equal element and so on
I hope that I find solution to my problem
thanks alot
 03152010, 05:25 PM #2Member
 Join Date
 Dec 2009
 Posts
 59
 Rep Power
 0
sorry the code is
Java Code:for (int y=0; y< vector_temp.size(); y++){ Min_diff(vect_temp); nex_minr(vect_temp,next_point); for (int i=0; i< vect_diff.size(); i++){ String element_min= vect_diff.get(i).toString(); if( vect_min.contains(element_min)){ vec_ordering.add(element_min); _2nd_min_element= element_min; vec_temp.removeElement(next_point); next_point=_2nd_min_element; i= vect_diff.size(); }// end if condition } // end for (i)loop }// end for (y) loop
 03152010, 05:48 PM #3
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,409
 Blog Entries
 7
 Rep Power
 25
I read your explanation several times but it seems that I'm too stupid to understand it; can you supply a small example please?
kind regards,
Jos
 03152010, 07:09 PM #4Member
 Join Date
 Dec 2009
 Posts
 59
 Rep Power
 0
sorry for the bad explanation
the problem is as follows: I have vector named [COLOR="rgb(255, 0, 255)"]vect_temp[/COLOR] and I want to reorder elements in that vector
the function Min_diff(vect_temp , next_point)
will find all possible next elements giving it previous element which is [COLOR="rgb(255, 0, 255)"]next_point [/COLOR] and save them in vector named [COLOR="rgb(255, 0, 255)"]vect_diff[/COLOR]
the other function which is [COLOR="rgb(255, 0, 255)"]nex_min(vect_temp, next_point)[/COLOR] which finds the next possible elements and save them in vector named[COLOR="rgb(255, 0, 255)"] vect_min[/COLOR]
I'm able to find only one solution but I want to find all possible
let me give an example:
let the vect_temp contains elements [3,2,1,7,9]
I find the first element to be [3]
after calling function Min_diff, the vect_diff will contain [2,9]
after calling function nex_min, the vect_min will contain [2,9]
I have to save 2 in the vec_ordering so it contains [3,2] then calling functions Min_diff and nex_min to find next element of 2 and if I find next element of 2 I have to add it in the reodering vector
this is only one solution which I'm able to find my problem is that there is multiple elements in vect_diff and vect_min are equal the second solution will be is saving 9 instead of 2 so it will be [3,9] and then finding next elements util the reordering is performed for all vect_temp
I hope now that you can understand me
as I said I want to find all possible solutions each time vect_diff and vect_min generate multiple equal elements I have to first for the first equal element and then calling functions to perform the reordering and get solution then perform ordering if you add other equal elements
the code I made for only one solution is:
Java Code:for (int y = 0; y < vect_temp.size(); y++) { Min_diff(vect_temp); nex_minr(vect_temp, next_point); for (int i = 0; i < vect_diff.size(); i++) { String element_min = vect_diff.get(i).toString(); if (vect_min.contains(element_min)) { vec_ordering.add(element_min); _2nd_min_element = element_min; vec_temp.removeElement(next_point); next_point = _2nd_min_element; i = vect_diff.size(); }// end if condition } // end for (i)loop }// end for (y) loop
 03162010, 07:30 AM #5Member
 Join Date
 Dec 2009
 Posts
 59
 Rep Power
 0
hello everyone
I have problem in finding all possible solutions for reordering of vector.
I have vector named (vect_temp) and I want to find all possible reordering of this vector.
I have function named Min_diff(vect_temp,next_point) works as follows : I should gave it an element (next_point) in the vector (vect_temp) and it must generate the vector (vect_diff) that contains all possible elements next elements.
The function nex_min(vect_temp,next_point) works as follows : I should gave it an element (next_point) in the vector (vect_temp) and it must generate the vector (vect_min) that contains all possible elements next elements.
reordering critriea:
Min_diff(vect_temp,next_point) and nex_min(vect_temp,next_point) and (next_point) in this first iteration is equal to any selected element in the (vect_temp). after calling the functions, if element in the (vect_diff) is equal to the element in ( vect_min) then add this element into the ordered set [ vec_ordering] and call functions Min_diff(vect_temp,next_point) and nex_min(vect_temp,next_point) again , next_point now is the equal to the element that we have been added in the previous step into the ordered set [ vec_ordering] and repeat this process until all elements in (vect_temp) are ordered according to this criteria.
 I'm able to do reordering according to the cirtira above and find one solution. but the problem is that if (vect_diff) contains many elements that equal to many elements in ( vect_min), in this case I need to do reordering for the first equal element and this will be one solution and then find reordering for the next equal element and so on.
let's consider this example:
 let (vect_temp) contains element [5,9,7,3,1]
 for the firs iteration let the next_point equal to 7
 after calling function Min_diff(vect_temp,next_point), then (vect_diff) will contain [ 5,9,3]
 after calling function nex_min(vect_temp,next_point), then ( vect_min) will contain [ 5,9]
so for now (vect_diff) and ( vect_min) will have two equal elements.
 the first solution must be that fist take the first equal element and do reordering such that ordered set [ vec_ordering] will equal to [7,5] then call functions Min_diff(vect_temp,next_point), and nex_min(vect_temp,next_point) again. the( next_point) in this iteration is qual to 5, these funtions will find next elements, let's consider that (vect_diff) and ( vect_min) will have equal element [3] then add this element to the ordered set [ vec_ordering] and repeat calling functions util all elments in (vect_temp) are added to the ordered set [ vec_ordering]. This will be one solution. now the second solution will be is to take second equal elment [9] instead of [5] and continue calling functions and finding ordered list.
so that each time vect_diff and vect_min will have many equal elements, then do reordering for first equal element this is one solution and then do reordering for the second equal element and so on.
my code that can only find one solution that takes only first equal element in (vect_diff) and ( vect_min) and continue ordering is below
Java Code:for (int y = 0; y < vect_temp.size(); y++) { Min_diff(vect_temp); nex_min(vect_temp, next_point); for (int i = 0; i < vect_diff.size(); i++) { String element_min = vect_diff.get(i).toString(); if (vect_min.contains(element_min)) { vec_ordering.add(element_min); _2nd_min_element = element_min; vec_temp.removeElement(next_point); next_point = _2nd_min_element; i = vect_diff.size(); }// end if condition } // end for (i)loop }// end for (y) loop
 03162010, 08:11 AM #6
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,409
 Blog Entries
 7
 Rep Power
 25
I still don't understand your explanation, but if you want all orders (permutations) of a sequence p_1, p_2, p_3 ... p_n the following iterative algorithm gives you a next permutation given a current permutation:
1) find the largest i such that p_i < p_(i+1)
2) if no such i exist, stop
3) find the largest j > i such that p_i < p_j (such j always exists)
4) swap p_i and p_j
5) reverse the sequence p_(i+1), p_(i+2) ... p_n
For example let the current permutation be acedb, so i == 2 (c < e) and
j == 4 (c < d); swap p_i and p_j: adecb. and reverse the sequence to the right of i: adbce; this is your next permutation in lexicographical order. This algorithm also works with duplicates in the sequence.
kind regards,
JosLast edited by JosAH; 03162010 at 04:06 PM.
 03162010, 09:00 AM #7Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,712
 Rep Power
 15
Also at forums.sun.com
 03162010, 09:35 AM #8Member
 Join Date
 Dec 2009
 Posts
 59
 Rep Power
 0
Similar Threads

what is natural ordering???
By blueduiker in forum New To JavaReplies: 1Last Post: 02242010, 11:51 AM 
getting all possible ordering of vector
By sara12345 in forum New To JavaReplies: 3Last Post: 01082010, 11:21 PM 
Problem with ordering for loops
By ScaryJello in forum New To JavaReplies: 3Last Post: 03312009, 08:20 PM 
Finding elements in a vector
By Java Tip in forum java.langReplies: 0Last Post: 04142008, 08:37 PM
Bookmarks