Avatar of ZURINET
ZURINET

asked on 

Clear Vector list

Hi all

I have the attached code..
For every single interation of method  <<public void one_iteration(int t) >>
a value of g is added to besFit Vector :::  bestFit.add(g);
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..

Thanks in Advance      
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);
				}
		}
	}
}

Open in new window

Java

Avatar of undefined
Last Comment
ZURINET
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Why - what happens when you don't?
Avatar of for_yan
for_yan
Flag of United States of America image



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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
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.
See Pricing Options
Start Free Trial
Avatar of for_yan
for_yan
Flag of United States of America image

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();

Avatar of for_yan
for_yan
Flag of United States of America image


As CellNode is something that supposedly you wrote yourself.
You probably provided method add, as we see in your code,

 bestFit.add(g);  

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



ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Blurred text
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.
Avatar of ZURINET
ZURINET

ASKER

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..

Avatar of ZURINET
ZURINET

ASKER

Hi
Yes CellNode is a class,

Avatar of for_yan
for_yan
Flag of United States of America image

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

ASKER

bestFit an instance of CellNode and CellNode is a collection
Avatar of for_yan
for_yan
Flag of United States of America image

But you have a constructor like that:

 new CellNode(xBMap,yBMap, xBMap)

Do you have the code for CellNode?
Post the code.
Avatar of for_yan
for_yan
Flag of United States of America image

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
.add(..) as you have in bestFit.add

Please, look attentively at your code and consider which
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

Avatar of ZURINET
ZURINET

ASKER

Hi all

It quite clear to me that the question definition is not quite clear..
However.. after reading your notes.

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 
}

Open in new window

Avatar of ZURINET
ZURINET

ASKER

Question was resolved based on the idea.. received from experts..
Java
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
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo