Help, need to add two integers to a queue and check if they are in there later

M

Mark

Hi all, I am trying to write a tabu search algorithm for my scheduling
program, but have hit a problem with the tabu list.

I am using java 1.5 and creating a queue object as shown...

Queue tabuList = new LinkedList();

I need to add a move to the tabu list, a move consists of two integers
in my program, (I swap two elements in a vector, the ints represent
the position of the object in the vector)

I have tried to add the two ints as an array and then run the
..contains() on the tabulist, but that will not work, (code shown
below)

tabuList.add(new int[](1,2));

if (tabuList.contains(new int[](1,2)){
System.out.println("yes");
}else{
System.out.println("no");
}

This i believe is because the int[] are objects with different
references, I thought about creating two tabuLists and add one int to
each list in the same position, but I cannot get the position of the
int in the tabu list.

Hope this all makes sense,

Any help would be fantastic

Mark
 
R

R.F. Pels

Mark said:
tabuList.add(new int[](1,2));

Uhm, wrap the move in a class:

public class Move
implements Comparable
{

public Move(int x, int y)
{
this.x = x;
this.y = y;
}

public int compareTo(Object o)
{
int result = 0; // Assume equality
if (o instanceof Move)
{
Move that = (Move) o;
result = x - that.x;
if (result == 0)
{
result = y - that.y;
}
}
else
{
throw new ClassCastException(o + " is not a Move object");
}
return result;
}

public int getX()
{
return x;
}

public void setX(int x)
{
this.x = x;
}

public int getY()
{
return y;
}

public void setY(int y)
{
this.y = y;
}

private int x;
private int y;
}

and use a Set to store them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top