package heuristics;

import java.util.HashMap;

import problem.Element;
import problem.Knapsack;

/**
 * TODO add javadoc
 * @author jorgebg90
 *
 */
public class TabuSearch extends Heuristic {

	/**Tabu list with the worst elements of the KS*/
	HashMap<Integer, Element> tabuList;
	
	/** Knapsack that contains the best solution*/
	private Knapsack bSol;
	/** Knapsack that contains the actual solution*/
	private Knapsack aSol;
	/** Knapsack that contains the temporal solution*/
	private Knapsack btSol;
	
	/**Temporal element that maintains the current best solution*/
	private Element tElement;
	/**Number of iterations that is given by the Agent class*/
	private int iT;
	
	public TabuSearch() {
		// TODO delete
	}
	
	/**
	 * 
	 * @param kInherited knapsack inherited from agent class
	 * @param nIter max number of iterations for the execution
	 * 
	 */
	
	
	public TabuSearch(int nIter, Knapsack kInherited)
	{
	
		this.bSol=kInherited;
		this.iT = nIter;
		
	}

	@Override
	public Knapsack executeOnce(Knapsack knapsack) {
		
		
		// TODO Auto-generated method stub
		
		return null;
	}
	
	public Knapsack TabuSearch ()
	{
		
		//In the first iteration, the best solution is given by the agent
		btSol = bSol;
		
		// tElement contains a random element value from Agent propose
		tElement = btSol.copyNotInsertedElements().get(0); /*Random value*/
		
		//It iterates a defined number of steps given by the Agent
		
			for (int j=0; j<= btSol.copyNotInsertedElements().size();j++)
			{
				if(tElement.getWeight() >  btSol.copyNotInsertedElements().get(j).getWeight())
				{
					
					
				}
				

				if(btSol.calculateTotalWeight() + tElement.getWeight() <= bSol.getCapacity()){
									
					//The element is swapped from notInsertedElement list to inserted Element list
					
					}

				
				else{
					break;
				}
				
				
			}
			
		
		
		
		return bSol;
	}
}

package heuristics;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Queue;
import java.util.Random;

import problem.Element;
import problem.Knapsack;

/**
 * TODO add javadoc
 * @author jorgebg90
 *
 */
public class TabuSearch extends Heuristic {

	/**Tabu list with the worst elements of the KS*/
	private Queue <Element> tabuList;
	
	/** List of the possible candidates in the neighborhood*/
	private ArrayList <Element> candidateList;
	
	/** Knapsack that contains the best solution*/
	private Knapsack bestSol;

	//*Index to iterates the knapsack*/
	private int i=0;
	
	//** It contains the closed neighborhood*/
	private ArrayList <Knapsack> neighborhood;
	
	
		/**
		 * 
		 * @param kInherited knapsack inherited from agent class
		 * 
		 */
		
		
		public TabuSearch(Knapsack kInherited){
			this.bestSol=kInherited;
		}

		@Override
		public Knapsack executeOnce(Knapsack knapsack) {
			
			//The Tabu list in the first instance must be empty
			tabuList=null;
			
			HashMap<Integer, Element> inserted = knapsack.copyInsertedElements();
			HashMap<Integer, Element> notInserted = knapsack.copyNotInsertedElements();
			
			
			
			while(!bestSol.isFull()){
				
				/**The candidate list is empty at first instance*/
				candidateList = null;		
				
				/**It obtains a r index to give back a key to preserve the neighborhood*/
				Random r = new Random();	
				int n = r.nextInt(10)+1;
				
				/**It creates a random neighborhood*/
				for(int i = 0; i < n; i++){
					neighborhood.add(new Knapsack(bestSol));
					
					
				}
				
				
				/**This part compares if the candidate is included in the tabuList*/
				for(){
									
					if(tabuList.isEmpty()){
						
						candidateList.add(sCandidate);			
					}
					else{
						if(!tabuList.contains(sCandidate)){
							candidateList.add(sCandidate);
							
						}						
					}
				}
				
				/***/
				
					
				}
					
				
				
				
			
			
			
			
					
	
				
			
			
			
			return bSol;
		}
				
	}
	


Update Sunday 19:41 Jorge