Guest User

Untitled

a guest
Dec 6th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import com.sun.deploy.util.StringUtils;
  2.  
  3. import javax.swing.text.StringContent;
  4. import java.util.List;
  5. import java.util.PriorityQueue;
  6.  
  7.  
  8. /**
  9. * Created by אביב on 11/30/2016.
  10. */
  11. public class UCS {
  12. private PriorityQueue<Node> queue;
  13. private GameTactic gt;
  14.  
  15. public UCS(GameTactic gt) {
  16. this.queue=new PriorityQueue<Node>(new UcsComparator());
  17. this.gt=gt;
  18. }
  19.  
  20. public String SolveSearch(){
  21. int pathSize;
  22. int timeStamp=1;
  23. Node temp;
  24. Node begin=new Node(0,0);
  25. begin.setCost(0);
  26. begin.setTimeStamp(0);
  27. this.queue.add(begin);
  28. List<Node> tempList;
  29. int listSize;
  30. while(true) {
  31. if (this.queue.isEmpty()){
  32. return "no path";
  33. }
  34. temp=this.queue.poll();
  35. pathSize=temp.getPath().split("-").length;
  36.  
  37. if(this.gt.IsGoal(temp)){
  38. String result=temp.getPath();
  39. result=result+" "+Integer.toString(temp.getCost());
  40. return result;
  41. }
  42. tempList=gt.GetPossibleNeigh(temp,timeStamp);
  43. listSize=tempList.size();
  44. if(pathSize<=((this.gt.size*this.gt.size/2)+this.gt.size)){
  45. for(int i=0;i<listSize;i++) {
  46. //this.queue.add(tempList.get(i));
  47. if (!this.queue.contains(tempList.get(i))) {
  48. this.queue.add(tempList.get(i));
  49. } else {
  50.  
  51. }
  52. }
  53. }
  54. timeStamp++;
  55. }
  56. }
  57. }
Add Comment
Please, Sign In to add comment