예제 #1
0
파일: GraphSearch.cs 프로젝트: langeds/aima
		private bool alreadySeen(Node node) 
		{
			//return closed.contains(node.getState());
			//you must compare hashcode values, or they will never
			//evaluate to true!
			return closed.Contains(node.getState().GetHashCode());
		}
예제 #2
0
		public ArrayList expandNode(Node node, Problem problem) 
		{
			int heuristic = problem.getHeuristicFunction().getHeuristicValue(
				node.getState());
			//System.out.println("Expanding\n"+node.getState()+"\n"+"heuristic =
			// "+heuristic+"\n");

			ArrayList nodes = new ArrayList();
			ArrayList successors = problem.getSuccessorFunction().getSuccessors(
				node.getState());
			for (int i = 0; i < successors.Count; i++) 
			{
				Successor successor = (Successor) successors[i];
				Node aNode = new Node(node, successor.getState());
				aNode.setAction(successor.getAction());
				double stepCost = problem.getStepCostFunction().calculateStepCost(
					node.getState(), successor.getState(),
					successor.getAction());
				aNode.setStepCost(stepCost);
				aNode.addToPathCost(stepCost);
				nodes.Add(aNode);

			}
			metrics.set(NODES_EXPANDED, metrics.getInt(NODES_EXPANDED) + 1);
			//System.out.println("Nodes expanded = " +
			// metrics.getInt(NODES_EXPANDED));
			return nodes;
		}
예제 #3
0
파일: GraphSearch.cs 프로젝트: langeds/aima
		protected override void addExpandedNodesToFringe(NodeStore fringe, Node node,
			Problem problem) 
		{

			if (!(alreadySeen(node))) 
			{
				//it is critical here put the hashcode of the object
				//into the hashtable!!
				closed.Add(node.getState().GetHashCode(),"");
				fringe.add(expandNode(node,problem));

			}
		}
예제 #4
0
		public ArrayList search(Problem p) 
		{
			clearInstrumentation();
			Node current = new Node(p.getInitialState());
			Node neighbor = null;
			while (true) 
			{
				ArrayList children = expandNode(current, p);
				neighbor = getHighestValuedNodeFrom(children, p);

				if ((neighbor == null)
					|| (getValue(neighbor, p) <= getValue(current, p))) 
				{
					return SearchUtils.actionsFromNodes(current.getPathFromRoot());
				}
				current = neighbor;
			}

		}
예제 #5
0
		public ArrayList search(Problem p)
		{
			clearInstrumentation();
			Node current = new Node(p.getInitialState());
			Node next = null;
			ArrayList ret = new ArrayList();
			for (int step = 0; step < 1000; step = step + 1) 
			{
				double temp = scheduler.getTemp(step);
				if (temp == 0.0) 
				{
					String status = "not completed";
					if (p.isGoalState(current.getState())) 
					{
						status = "success";
					}
					//System.out.println(current.getState());
					ret = SearchUtils.actionsFromNodes(current.getPathFromRoot());
					ret.Add(status + "\nFinal state = \n" + current.getState());
					break;
				}
				ArrayList children = expandNode(current, p);
				//expansions++;
				//System.out.println("step = "+step+" expansions = "+expansions);
				if (children.Count > 0) 
				{
					//TODO take care of no possible expansion situation?
					next = (Node) Util.selectRandomlyFromList(children);
					int deltaE = getValue(next, p) - getValue(current, p);
					//System.out.print("deltaE = "+deltaE+"\n");
					if ((deltaE > 0.0)
						|| (new Random().NextDouble() > Math.Exp(deltaE / temp))) 
					{
						current = next;
					}
				}

			}
			//System.out.println("Number of expansions = "+expansions);
			return ret;//Total Failure
		}
예제 #6
0
		private ArrayList recursiveDLS(Node node, Problem problem, int limit) 
		{
			bool cutOffOccured = false;
			if (problem.isGoalState(node.getState())) 
			{
				return SearchUtils.actionsFromNodes(node.getPathFromRoot());
			} 
			else if (node.getDepth() == limit) 
			{
				return createCutOffResult();
			} 
			else 
			{
				ArrayList children = expandNode(node, problem);
				for (int i = 0; i < children.Count; i++) 
				{
					Node child = (Node) children[i];
					ArrayList result = recursiveDLS(child, problem, limit);
					if (cutoffResult(result)) 
					{
						cutOffOccured = true;
					} 
					else if (!(failure(result))) 
					{
						return result;
					}
				}
				if (cutOffOccured) 
				{
					return createCutOffResult();
				} 
				else 
				{
					return new ArrayList();
				}

			}

		}
예제 #7
0
파일: QueueSearch.cs 프로젝트: langeds/aima
		protected abstract void addExpandedNodesToFringe(NodeStore fringe,
			Node node, Problem p);
예제 #8
0
		public void add(Node anItem) 
		{
			queue.add(anItem);

		}
예제 #9
0
파일: Node.cs 프로젝트: langeds/aima
		public Node(Node parent, Object state) : this(state)
		{
			//this(state);
			this.parent = parent;
			this.depth = parent.getDepth() + 1;
		}
예제 #10
0
		private int getValue(Node n, Problem p) 
		{
			return -1 * getHeuristic(n, p); //assumption greater heuristic value =>
			// HIGHER on hill; 0 == goal state;
			//SA deals with gardient DESCENT
		}
예제 #11
0
		private int getHeuristic(Node aNode, Problem p) 
		{
			return p.getHeuristicFunction().getHeuristicValue(aNode.getState());
		}
예제 #12
0
파일: TreeSearch.cs 프로젝트: langeds/aima
		protected override void addExpandedNodesToFringe(NodeStore fringe, Node node,
			Problem problem) 
		{
			fringe.add(expandNode(node, problem));
		}