# Clear Vector list

Hi all

I have the attached code..
For every single interation of method  <<public void one_iteration(int t) >>
I need a way of clearing all the assingment to bestFit, before the next Interaton occours... given
the fact that there could be up to 50 interations..

``````Given that a sample g = (c1	0	0	1) is a vector
*****************************************************
c1	0	0	1
c2	0	1	0
c3	1	0	0
*****************************************************
public void one_iteration(int t){
CellNode bestFit;  //Class CellNode (0,0,0)
CellNode tempNode;
double [] wUpdate;
double varInflue;
double [] varW_Vector;

Gene[] random_order = shuffle();

for(int j=0; j<8.length; j++){
Gene g = random_order[j]; //Given than g = ()

bestFit =   find_best_Fit(g);
bestFit.add(g);  //Given that bestFit has a method clear_list : which clears all the g containt of bestFit

for(int i=0; i<6; i++)
{
int xBMap = map[i].get_x();
int yBMap = map[i].get_y();
currentNode = new CellNode(xBMap,yBMap, xBMap);

varW_Vector = map[i].get_weight_vector();
wUpdate = Function.update_weight_vector(varInflue, varW_Vector,currentNode);

if (varInflue > 0)
{
map[i].set_weight_vector(wUpdate);
}
}
}
}
``````
Java

Last Comment
ZURINET
CEHJ

>>I need a way of clearing all the assingment to bestFit

Why - what happens when you don't?
for_yan

That's how you declare bestFit:
CellNode bestFit

Is CellNode the class, which you defined?
Show the code which defines this class.
You need to define method clear_list() in this class yourself.
Or you can create new instance of it.
SOLUTION
CEHJ

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
for_yan

If your bestFit would indeed be an instance of a Vector or ArrayList
class or would extend this class,
then in both of these classes there is a method

clear(),

so you'd remove all elements of this container with

bestFit.clear();

for_yan

As CellNode is something that supposedly you wrote yourself.

So you should also provide method clear(),
which would remove all your elements.

for_yan

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
ZURINET

Hi all

The problem is that
bestFit =   find_best_Fit(g);
is used as a reference ... to indicate which vector to work with..
Hence after working with the vector ... I need to release the the g..
If g is not released the the value will be double during the next interation..

ZURINET

Hi
Yes CellNode is a class,

for_yan

But is bestFit an instance of CellNode or it is rather an instance of a vector, arraylist, basically is it a collection ?
ZURINET

bestFit an instance of CellNode and CellNode is a collection
for_yan

But you have a constructor like that:

new CellNode(xBMap,yBMap, xBMap)

Do you have the code for CellNode?
Post the code.
for_yan

In the CellNode code we should have both the constructor
which has three integeres like in
new CellNode(xBMap,yBMap, xBMap) (do you really need to have xbMap twice here?)
and it should have method

variables belong to which types.

It is best of all to type any Java code in the IDE - it would help
to keep code organized in terms of types and classes, and it would highlight all
undeclared varaibles or incompatible variable types, non-existing methods.
It very much helps to think when you are designing even small programs

ZURINET

Hi all

It quite clear to me that the question definition is not quite clear..

and my comment <<I need a way of clearing all the assingment to bestFit, before the next Interaton occours... >

I need to do clear before the loop is called  <<Gene[] random_order = shuffle();>>
Which I did with the code below..

Any way thanks for your input

Regards

``````for(int i=0; i<bestFit.length; i++)
{
bestFit.clear_list  //give that bestFit has a method clear_list
}
``````
ZURINET

Question was resolved based on the idea.. received from experts..
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts

TRUSTED BY