C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# fast heuristic algorithm for n queens (n > 1000)

By : Bryant Ezroj
Date : November 17 2020, 11:58 AM
I wish this helpful for you Note: This answer assumes you're interested in finding one valid solution. If you need to find all solutions, this won't help you.
Artificial Intelligence: A Modern Approach, Second Edition by Russell & Norvig has a table in Chapter 5: Constraint Satisfaction Problems on page 143 comparing various constraint satisfaction problem algorithms for various tasks. (The latest edition is the Third Edition, and it looks like Constraint Satisfaction Problems is now Chapter 6.)
code :
``````Starting Configuration:
14  0  2  13  12  17  10  14  14  2  9  8  11  10  6  16  0  7  10  8
Solution found
Ending Configuration:
17  2  6  12  19  5  0  14  16  7  9  3  1  15  11  18  4  13  8  10
Elapsed time (sec): 0.00167
Number of moves: 227
``````
``````Queens      ~Time(sec)
======      ==========
100           0.03
200           0.12
500           1.42
1000           9.76
2000          72.32
5000        1062.39
``````

Share :

## All or nothing - fast heuristic shortest path algorithm (parallel?)

By : user3174587
Date : March 29 2020, 07:55 AM
And talking about implementation on CUDA, you will have to remember that billions of nodes = Gigabytes of memory. That would provide a limitation on the nodes you can use per card (for optimum performance) at a time. The maximum capacity of a graphics card currently in the market is about 6GB. This can give you an estimate on the number of cards you may need to use (not necessarily the number of machines).

## Eight Queens Heuristic

By : Kaushik Gudapati
Date : March 29 2020, 07:55 AM
To fix this issue I am developing a heuristic to place 8 queens on 8x8 chessboard. each square has its own elimination number (to indicate how many squares of an empty chessboard are “eliminated” if a queen is placed in that square.) and the each queen should be placed in the square which has the lowest elimination number. , This piece of code is inherently flawed:
code :
``````for (int queen = 0; queen < queens.length; queen++) {
placeQueens(queen);
}
``````

## fast generating 1000 means of sample points from truncated gamma distriution with 1000 different shapes and scales value

By : Jay Hopia
Date : March 29 2020, 07:55 AM
I hope this helps . There are several things going on here.
First, you calculate the scales as:
code :
``````scale.list <- runif(1000, max = 100000, min = 100000)
``````
``````f <- function(shape,scale,lb,ub){
X <- rtrunc(1000, spec="gamma", a=lb, b=ub,shape=shape,scale=scale)
return(c(mean=mean(X),sd=sd(X)))
}
# set.seed(1)  # use this for a reproducible sample
result <- mapply(f,shape.list,scale.list, lb=20,ub=50)
result.apply <- data.frame(t(result))
``````

## Fast space partitioning heuristic?

By : Jaepil Jang
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , SOLUTION
I've found a heuristic that works great for my BSP tree purposes and which is also really interesting to analyze. In the code below, I first tried using a AABB tree to ask "which segments does this line intersect." But even this was too slow, so in the end I just went with a costly initial O(N^2) comparison algorithm that quickly speeds up as the BSP tree builds, using a somewhat clever observation!
code :
``````for all splitters s in S
s.posCount = s.negCount = s.introduced = s.saved = 0
for all splitters vs in S
if (s == vs) continue
if vs is fully on the positive side of the plane of s
s.posCount++
else if vs is fully on the negative side of the plane of s
s.negCount++
else if vs intersects the plane of s
s.negCount++, s.posCount++, s.introduced++
else if vs is coplanar with s
s.saved++
``````
``````evaluate(posCount, negCount, saved, introduced, treeDepth) {
float f;
if (treeDepth >= EVALUATE_X2) {
f = EVALUATE_V2;
} else if (treeDepth >= EVALUATE_X1) {
float r = treeDepth - EVALUATE_X1;
float w = EVALUATE_X2 - EVALUATE_X1;
f = ((w-r) * EVALUATE_V1 + r * EVALUATE_V2) / w;
} else {
f = EVALUATE_V1;
}

float balanceScore = -f * BALANCE_WEIGHT * abs(posCount - negCount);
float freedomScore = (1.0f-f) * (SAVED_WEIGHT * saved - INTRO_WEIGHT * introduced);
return freedomScore + balanceScore;
}
``````
``````#define BALANCE_WEIGHT 437
#define INTRO_WEIGHT 750
#define SAVED_WEIGHT 562
#define EVALUATE_X1 3
#define EVALUATE_X2 31
#define EVALUATE_V1 0.0351639f
#define EVALUATE_V2 0.187508f
``````
``````for all splitters s at this node
s.partner = null
if s == SEL then add s to "remnants"
else
if s is fully on the positive side of SEL
else if s is fully on the negative side of SEL
else if s intersects SEL
split s into two appropriate segments sp and sn
sp.partner = sn, sn.partner = sp
add sn to "negatives", sp to "positives" and s to "remnants"
else if s coplanar with SEL

// the clever bit
if (positives.size() > negatives.size())
calcRelationCounts(negatives)
updateRelationCounts(positives, negatives, remnants)
else
calcRelationCounts(positives)
updateRelationCounts(negatives, positives, remnants)

add positives and negatives to appropriate child nodes for further processing
``````
``````updateRelationCounts(toUpdate, removed, remnants) {
for all splitters s in toUpdate
for all splitters vs in removed, then remnants
if vs has a partner
if the partner intersects s
s.posCount++, s.negCount++, s.introduced++
else if the partner is fully on the positive side of s
s.posCount++
else if the partner is fully on the negative side of s
s.negCount++
else if the partner is coplanar with s
s.saved++
else
if vs intersects s
s.posCount--, s.negCount--, s.introduced--
else if vs is fully on the positive side of s
s.posCount--
else if vs is fully on the negative side of s
s.negCount--
else if vs is coplanar with s
s.saved--
``````

## Why greedy algorithm is heuristic, not meta-heuristic?

By : user3628641
Date : March 29 2020, 07:55 AM
Hope this helps There are a lot of greedy algorithms for different problems, greedy algorithm is not the one particular algorithm, it's a class of algorithms that use the same approach to the problem. Dijkstra's algorithm, Prim's algorithm, Kruskal's algorithm, etc. are completely different, but they are all greedy.
In Dijkstra's algorithm you take an untouched node with minimal distance to it. In Prim's algorithm you take an edge, that connects tree node with not-tree node, with minimal weight. In Kruskal's algorithm you take an edge, that connects two different trees, with minimal weight. And there are many greedy algorithms that don't even work with graphs.