<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="et">
	<id>http://www.lambda.ee/w/index.php?action=history&amp;feed=atom&amp;title=Ifi6057strategies</id>
	<title>Ifi6057strategies - Redigeerimiste ajalugu</title>
	<link rel="self" type="application/atom+xml" href="http://www.lambda.ee/w/index.php?action=history&amp;feed=atom&amp;title=Ifi6057strategies"/>
	<link rel="alternate" type="text/html" href="http://www.lambda.ee/w/index.php?title=Ifi6057strategies&amp;action=history"/>
	<updated>2026-10-28T14:22:24Z</updated>
	<subtitle>Selle lehekülje redigeerimiste ajalugu</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>http://www.lambda.ee/w/index.php?title=Ifi6057strategies&amp;diff=13298&amp;oldid=prev</id>
		<title>PriitJ: Uus lehekülg: &#039;8-Puzzle: vali ülesanne (&lt;code&gt;testprob&lt;/code&gt;) ja soovitav otsingustrateegia. Hoiatus: kõik strateegiad ei pruugi mõistliku aja jooksul valmis saada, eriti Pythonis.  Python ...&#039;</title>
		<link rel="alternate" type="text/html" href="http://www.lambda.ee/w/index.php?title=Ifi6057strategies&amp;diff=13298&amp;oldid=prev"/>
		<updated>2016-10-09T12:20:33Z</updated>

		<summary type="html">&lt;p&gt;Uus lehekülg: &amp;#039;8-Puzzle: vali ülesanne (&amp;lt;code&amp;gt;testprob&amp;lt;/code&amp;gt;) ja soovitav otsingustrateegia. Hoiatus: kõik strateegiad ei pruugi mõistliku aja jooksul valmis saada, eriti Pythonis.  Python ...&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Uus lehekülg&lt;/b&gt;&lt;/p&gt;&lt;div&gt;8-Puzzle: vali ülesanne (&amp;lt;code&amp;gt;testprob&amp;lt;/code&amp;gt;) ja soovitav otsingustrateegia. Hoiatus: kõik strateegiad ei pruugi mõistliku aja jooksul valmis saada, eriti Pythonis.&lt;br /&gt;
&lt;br /&gt;
Python (pane &amp;lt;code&amp;gt;aima-python-master&amp;lt;/code&amp;gt; kataloogi):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#eight.py&lt;br /&gt;
&lt;br /&gt;
import search&lt;br /&gt;
&lt;br /&gt;
badmoves = {4 : 3, 7: 6, 3 : 4, 6 : 7} # &amp;quot;teleporting&amp;quot; across board&lt;br /&gt;
&lt;br /&gt;
class EightPuzzle(search.Problem):&lt;br /&gt;
    def actions(self, state):&lt;br /&gt;
        al = []&lt;br /&gt;
        tyhik = state[0]&lt;br /&gt;
        for offset in [-3, -1, 1, 3]:&lt;br /&gt;
            koht = tyhik + offset&lt;br /&gt;
            if koht &amp;gt;= 1 and koht &amp;lt;= 9 and badmoves.get(tyhik) != koht:&lt;br /&gt;
                al.append(koht)&lt;br /&gt;
        return al&lt;br /&gt;
&lt;br /&gt;
    def result(self, state, action):&lt;br /&gt;
        newstate = [action]&lt;br /&gt;
        for el in state[1:]:&lt;br /&gt;
            if el == action:&lt;br /&gt;
                newstate.append(state[0])&lt;br /&gt;
            else:&lt;br /&gt;
                newstate.append(el)&lt;br /&gt;
        return tuple(newstate)&lt;br /&gt;
&lt;br /&gt;
    def goal_test(self, state):&lt;br /&gt;
        return self.goal == state&lt;br /&gt;
&lt;br /&gt;
GOAL = (9, 1, 2, 3 ,4 ,5, 6, 7, 8)&lt;br /&gt;
&lt;br /&gt;
def test(initial, searchfunc):&lt;br /&gt;
    p = EightPuzzle(initial, GOAL)&lt;br /&gt;
    ip = search.InstrumentedProblem(p)&lt;br /&gt;
    n=searchfunc(ip)&lt;br /&gt;
&lt;br /&gt;
    # expanded/goal tests/leaves/(solution)&lt;br /&gt;
    print (ip)&lt;br /&gt;
    if hasattr(n, &amp;quot;path&amp;quot;):&lt;br /&gt;
        print (n.path())&lt;br /&gt;
    else:&lt;br /&gt;
        print (n)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    a = (7, 2, 5, 3 ,1 ,8, 6, 4, 9)&lt;br /&gt;
    b = (5, 2, 6, 3, 4, 9, 8, 7, 1)&lt;br /&gt;
    c = (4, 2, 3, 8, 1, 9, 7, 6, 5)&lt;br /&gt;
&lt;br /&gt;
    testprob = a&lt;br /&gt;
&lt;br /&gt;
    test(testprob, search.breadth_first_tree_search)&lt;br /&gt;
    #test(testprob, search.breadth_first_search)&lt;br /&gt;
    #test(testprob, search.depth_first_tree_search)&lt;br /&gt;
    #test(testprob, search.depth_first_graph_search)&lt;br /&gt;
    def dls(param):&lt;br /&gt;
        return search.depth_limited_search(param, 7)&lt;br /&gt;
    #test(testprob, dls)&lt;br /&gt;
    #test(testprob, search.iterative_deepening_search)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Java (pane &amp;lt;code&amp;gt;aima-gui/src/main/java/aima/gui/demo/search&amp;lt;/code&amp;gt; kataloogi):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//eight.java&lt;br /&gt;
&lt;br /&gt;
package aima.gui.demo.search;&lt;br /&gt;
&lt;br /&gt;
import java.util.Iterator;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
import java.util.Properties;&lt;br /&gt;
&lt;br /&gt;
import aima.core.agent.Action;&lt;br /&gt;
import aima.core.environment.eightpuzzle.EightPuzzleBoard;&lt;br /&gt;
import aima.core.environment.eightpuzzle.EightPuzzleFunctionFactory;&lt;br /&gt;
import aima.core.search.framework.GoalTest;&lt;br /&gt;
import aima.core.search.framework.GraphSearch;&lt;br /&gt;
import aima.core.search.framework.Problem;&lt;br /&gt;
import aima.core.search.framework.Search;&lt;br /&gt;
import aima.core.search.framework.SearchAgent;&lt;br /&gt;
import aima.core.search.framework.TreeSearch;&lt;br /&gt;
import aima.core.search.uninformed.BreadthFirstSearch;&lt;br /&gt;
import aima.core.search.uninformed.DepthFirstSearch;&lt;br /&gt;
import aima.core.search.uninformed.DepthLimitedSearch;&lt;br /&gt;
import aima.core.search.uninformed.IterativeDeepeningSearch;&lt;br /&gt;
&lt;br /&gt;
class MyGoalTest implements GoalTest {&lt;br /&gt;
	EightPuzzleBoard goal = new EightPuzzleBoard(new int[] { 1, 2, 3, 4, 5,&lt;br /&gt;
			6, 7, 8, 0 });&lt;br /&gt;
&lt;br /&gt;
	public boolean isGoalState(Object state) {&lt;br /&gt;
		EightPuzzleBoard board = (EightPuzzleBoard) state;&lt;br /&gt;
		return board.equals(goal);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class eight {&lt;br /&gt;
	static void test(EightPuzzleBoard initial, Search searchfunc) {&lt;br /&gt;
		try {&lt;br /&gt;
			Problem problem = new Problem(initial, EightPuzzleFunctionFactory&lt;br /&gt;
					.getActionsFunction(), EightPuzzleFunctionFactory&lt;br /&gt;
					.getResultFunction(), new MyGoalTest());&lt;br /&gt;
&lt;br /&gt;
			SearchAgent agent = new SearchAgent(problem, searchfunc);&lt;br /&gt;
			printInstrumentation(agent.getInstrumentation());&lt;br /&gt;
			printActions(agent.getActions());&lt;br /&gt;
		} catch (Exception e) {&lt;br /&gt;
			e.printStackTrace();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	static EightPuzzleBoard a = new EightPuzzleBoard(&lt;br /&gt;
			new int[] { 4, 1, 3, 7, 2, 6, 0, 5, 8 });&lt;br /&gt;
&lt;br /&gt;
	static EightPuzzleBoard b = new EightPuzzleBoard(&lt;br /&gt;
			new int[] { 8, 1, 3, 4, 0, 2, 7, 6, 5 });&lt;br /&gt;
&lt;br /&gt;
	static EightPuzzleBoard c = new EightPuzzleBoard(&lt;br /&gt;
			new int[] { 4, 1, 2, 0, 8, 7, 6, 3, 5 });&lt;br /&gt;
&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		EightPuzzleBoard testprob = a;&lt;br /&gt;
&lt;br /&gt;
		test(testprob, new BreadthFirstSearch(new TreeSearch()));&lt;br /&gt;
//		test(testprob, new BreadthFirstSearch(new GraphSearch()));&lt;br /&gt;
//		test(testprob, new DepthFirstSearch(new TreeSearch()));&lt;br /&gt;
//		test(testprob, new DepthFirstSearch(new GraphSearch()));&lt;br /&gt;
//		test(testprob, new DepthLimitedSearch(7));&lt;br /&gt;
//		test(testprob, new IterativeDeepeningSearch());&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	private static void printInstrumentation(Properties properties) {&lt;br /&gt;
		Iterator&amp;lt;Object&amp;gt; keys = properties.keySet().iterator();&lt;br /&gt;
		while (keys.hasNext()) {&lt;br /&gt;
			String key = (String) keys.next();&lt;br /&gt;
			String property = properties.getProperty(key);&lt;br /&gt;
			System.out.println(key + &amp;quot; : &amp;quot; + property);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	private static void printActions(List&amp;lt;Action&amp;gt; actions) {&lt;br /&gt;
		for (int i = 0; i &amp;lt; actions.size(); i++) {&lt;br /&gt;
			String action = actions.get(i).toString();&lt;br /&gt;
			System.out.println(action);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>PriitJ</name></author>
	</entry>
</feed>