问题描述
更新
更新1
我想这个(2号线):我添加节点改变颜色第一指令字母a的功能。我越来越这个结果:
绿色节点访问节点。它看起来像,算法是正确的去扔节点,对不对?但如何输出正确的价值观中的节点 - 我还需要做到这一点?儿童值最小,最大的孩子值(不包括修剪树枝)。对
更新2
我试图输出α和β的树节点,并没有得到正确的结果。 这是code(第18行和31加)。 这是的code结果:
在这个图像I显示奇怪的地方:
第一个箭头:为什么最小的7和6是5?第二个箭头:为什么最多4个,3个和2个是5?奇怪。这就是为什么我认为,现在是正常工作。
老问题
很久以前我在这里创建了类似的问题。它是这样的:为什么我得到这个错误?。让我们回滚和创造新的。这个问题将是:如何显示阿尔法贝塔剪枝算法结果
我发现伪$ C $该算法在维基℃。可以发现这里。
我实现低于(这是JavaScript的,但我不认为要回答这个问题,你必须知道JS或Java或C ++等)。现在的问题是如何在这个算法上图(树形结构)的输出结果呢?在开始我有这样的树形结构:
注意:我的树状结构(一定量联节点
S),关于这一点我会用α+β剪枝算法,和我还有一个树状结构(用于显示的结果,让我们把它称为图形)。树的节点,我用它来显示图形与节点,我用它来寻找算法的结果连接起来。
所以,$ C $的α+β修剪algroithm的c是如下。你能澄清什么,在哪里我都输出到正确显示该算法的过程/结果,请?
我的假设是输出α和β,但我认为,这是错误的。我尝试过,但它不工作。
我要显示剪枝,并填写在用正确的值树中的所有节点。
这是我实现极小的与α+β修剪:
功能字母a(节点,深度,α,β,isMax,G){
如果((深度== 0)||(node.isTerminal ==真)){
返回node.value;
}
如果(isMax){
的console.log('最大化');
对于(VAR我在node.children){
VAR的孩子= node.children [I]
执行console.log(子);
阿尔法= Math.max(α,字母a(孩子,深度1,α,β,假,G));
如果(测试版< =阿尔法){
的console.log('测试版'+测试+'阿尔法'+字母);
打破;
}
}
返回阿尔法;
} 其他 {
的console.log('最小化');
对于(VAR我在node.children){
的console.log(1名儿童');
VAR的孩子= node.children [I]
执行console.log(子);
公测= Math.min(测试版,字母a(孩子,深度1,α,β,真实,G));
如果(测试版< =阿尔法){
的console.log('测试版'+测试+'阿尔法'+字母);
打破;
}
}
回归测试;
}
}
为什么你不只是存储的实际访问节点和颜色这些节点红色。然后你会看到比整个树的节点得到了评估。例如,
在在评论中进行了长时间讨论,我想我现在可以阐明这个角度。由于α+β绕着树,它有三个值,一个给定的节点上运行时,它有α和β进行到它从其父节点,然后它最大的价值是迄今发现。如果发现α-β窗口外的值,它会立即修剪,因为它知道这点是不是最优的举动,不管它的价值。因此,对于某些节点α+β永远不会奏效了真正价值的节点。
因此,当你被要求显示结果阿尔法测试版,我误以为你的意思是α-β窗口,自真正价值永远不会必然评估。
您需要编写单独的code打印真节点值。我认为这极大极小算法为你做这个。
此外,由专人,如果您使用的是套的节点,列表迭代不保证返回的节点在predictable为了比较的时候要注意,如果在节点内使用的是套而不是列出,您可能会发现它很难用手工遵循。列表迭代器返回的插入顺序。设置迭代器没有predictable迭代器。
Updates
Update 1
I tried this (2nd line): I added changing node color as first instruction in alphabeta function. I am getting this result:
Green nodes are visited nodes. It looks like, algorithm is going throw nodes correctly, right? But how to output correct values in nodes — I also need to do this? Minimum of children values, maximum of children values (excluding pruned branches).
Update 2
I tried to output alpha and beta to the tree nodes and didn't get correct result. This is code (line 18 and 31 were added). This is result of the code:
On this image I show strange places:
First arrow: why minimum of 7 and 6 is 5? Second arrow: why maximum of 4, 3 and 2 is 5? Strange. Thats why I think, that it is now working correctly.
Old question
Once upon a time I created similar question here. It was like: "why I get this error?". Lets rollback and created new one. This question will be: "How to display Alpha Beta Pruning algorithm result?"
I found pseudocode of this algorithm on the wiki. It can be found here.
My realization is below (it is on JavaScript, but I don't think that to answer this question you have to know JS or Java or C++ etc). The question is how to output result of this algorithm on the graph (tree structure)? On start I have this tree structure:
NOTE: I have tree structure (some amount of linked node
s), on which I will use alpha beta pruning algorithm, and I have another tree structure (for displaying results, lets call it "graph"). Nodes of tree, which I use to display graph are connected with nodes, which I use to find result of the algorithm.
So, code of the alpha beta pruning algroithm is below. Can you clarify what and where I have to output to display process/results of the algorithm correctly, please?
My assumption is to output alpha and beta, but I think, it is wrong. I tried it, but it doesn't work.
I want to display prunings and fill in all nodes in the tree with correct values.
This is my realization of minimax with alpha beta pruning:
function alphabeta(node, depth, alpha, beta, isMax, g) {
if((depth == 0) || (node.isTerminal == true)) {
return node.value;
}
if(isMax) {
console.log('maximizing');
for (var i in node.children) {
var child = node.children[i];
console.log(child);
alpha = Math.max(alpha, alphabeta(child, depth-1, alpha, beta, false, g));
if(beta <= alpha) {
console.log('beta '+beta+' alpha '+alpha);
break;
}
}
return alpha;
} else {
console.log('minimizing');
for (var i in node.children) {
console.log('1 child');
var child = node.children[i];
console.log(child);
beta = Math.min(beta, alphabeta(child, depth-1, alpha, beta, true, g));
if (beta <= alpha) {
console.log('beta '+beta+' alpha '+alpha);
break;
}
}
return beta;
}
}
Why don't you just store the nodes that are actually visited, and colour those nodes Red. Then you will see which nodes got evaluated compared to the entire tree. E.g.
After a long discussion in the comments, I think I can now shed light on this. As the alpha beta goes around the tree, it has three values, when operating on a given node, it has the alpha and beta that were carried down to it from its parent node, and then it has the best value it has found so far. If it finds a value outside the alpha-beta window, it immediately prunes, as it knows that this node is not an optimal move, irrespective of its value. Thus, for some nodes alpha beta never works out the "true value" of the node.
Thus, when you are asked to display the "result" of alpha beta, I mistakenly thought that you meant the alpha-beta window, since the "true value" is never necessarily evaluated.
You would need to write separate code to print the "true node values". I think that the minimax algorithm will do this for you.
Also, be aware when comparing by hand that if you are using a "set" of nodes, the list iterator is not guaranteed to return the nodes in a predictable order, so if inside the nodes you are using sets rather than lists, you might find that its hard to follow by hand. List iterators return in insertion order. Set iterators have no predictable iterator.
这篇关于如何显示阿尔法贝塔剪枝算法的结果呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!