Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


[Haskell] Constraint programming - Ramsey's theorem filter_list
Author
Message
[Haskell] Constraint programming - Ramsey's theorem #1
Here is an explanation for Ramsey's theorem (https://en.wikipedia.org/wiki/Ramsey%27s_theorem):

Quote:In combinatorics, Ramsey's theorem states that in any colouring of the edges of a sufficiently large complete graph, one will find monochromatic complete subgraphs. For 2 colours, Ramsey's theorem states that for any pair of positive integers (r,s), there exists a least positive integer R(r,s) such that for any complete graph on R(r,s) vertices, whose edges are coloured red or blue, there exists either a complete subgraph on r vertices which is entirely blue, or a complete subgraph on s vertices which is entirely red. Here R(r,s) signifies an integer that depends on both r and s. It is understood to represent the smallest integer for which the theorem holds.


This is a possible solution for R(3,3):

[Image: 210px-RamseyTheory_K5_no_mono_K3.svg.png]

That means this complete graph with 5 vertices is colored in red and blue so that there is no subgraph with 3 vertices (a triangle) that has only one color.

Using the MiniSat (that is an open source SAT solver) I can get a solution for this particular problem in Haskell. The first problem is always to find a way to code the problem. In this case a matrix of booleans is suitable whereas True means blue and False means red.
Since the graph is undirected you can ignore the lower half of it. Also there is no node that has a connection to itself (the graph is not reflexive). So the diagonal can be ignored too.

The matrix for the above solution will look like this, if I numbered the nodes clockwise from 1 to 5.

n 1 2 3 4 5
1 - f t t f
2 - - f t t
3 - - - f t
4 - - - - f
5 - - - - -

t = true (blue)
f = false (red)
- = is ignored

Here is the code for solving a R(3, 3) problem. The SAT solver prints out the matrix values if there is a solution. (I didn't write everything on my own, it was a homework for a course at university)

Code:
import Satchmo.Boolean
import Satchmo.SAT.Mini
import Satchmo.Code

import Control.Monad (forM)
import Prelude hiding (not, and, or)

test :: Int -> IO ( Maybe [[Bool]] )
test n = solve $ do
  edges <- forM [0..n-1] $ \i ->
    forM [0..n-1] $ \j ->
      boolean
  forM [0..n-1] $ \x ->
    forM [x+1..n-1] $ \y ->
      forM [y+1..n-1] $ \z -> do
        notAllRed <- or [ edges !! x !! y
          , edges !! x !! z
          , edges !! y !! z ]
        allBlue <- and [ edges !! x !! y
          , edges !! x !! z
          , edges !! y !! z ]

        both <- and [ notAllRed, not allBlue ]
        assert [ both ]
  return $ decode edges
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Haskell] Constraint programming - Ramsey's theorem #2
Oh wow, it's been a while I have seen anything like this. Takes me back to when I was studying decision mathematics. The beauty of these theories is that they're purely algorithms and thus form a nice intersection between computer science and mathematics. For example (please correct me if I'm wrong) I believe Dijkstra's algorithm still has applications in route mapping for 'real' systems. Would be great to see any more work you have done on similar subjects. Deque, my hat goes off to you sir.
“The first principle is that you must not fool yourself and you are the easiest person to fool.” - Feynman

Reply

RE: [Haskell] Constraint programming - Ramsey's theorem #3
Oh wow, it's been a while I have seen anything like this. Takes me back to when I was studying decision mathematics. The beauty of these theories is that they're purely algorithms and thus form a nice intersection between computer science and mathematics. For example (please correct me if I'm wrong) I believe Dijkstra's algorithm still has applications in route mapping for 'real' systems. Would be great to see any more work you have done on similar subjects. Deque, my hat goes off to you sir.
“The first principle is that you must not fool yourself and you are the easiest person to fool.” - Feynman

Reply

RE: [Haskell] Constraint programming - Ramsey's theorem #4
Oh wow, it's been a while I have seen anything like this. Takes me back to when I was studying decision mathematics. The beauty of these theories is that they're purely algorithms and thus form a nice intersection between computer science and mathematics. For example (please correct me if I'm wrong) I believe Dijkstra's algorithm still has applications in route mapping for 'real' systems. Would be great to see any more work you have done on similar subjects. Deque, my hat goes off to you sir.
“The first principle is that you must not fool yourself and you are the easiest person to fool.” - Feynman

Reply

RE: [Haskell] Constraint programming - Ramsey's theorem #5
(02-09-2013, 04:17 PM)-ELM Wrote: Oh wow, it's been a while I have seen anything like this. Takes me back to when I was studying decision mathematics. The beauty of these theories is that they're purely algorithms and thus form a nice intersection between computer science and mathematics. For example (please correct me if I'm wrong) I believe Dijkstra's algorithm still has applications in route mapping for 'real' systems. Would be great to see any more work you have done on similar subjects. Deque, my hat goes off to you sir.

Thank you, Sir. I didn't expect that anyone would still comment on this one. It doesn't seem that many people here are interested in mathematics.
I am just a computer scientist, no mathematician, thus I believe you have more knowledge than me on this topic. And it is madam. Thank you for your comment. Smile
For Dijkstra's Algorithm: I honestly don't know which algorithm is implemented in map routing software today, but I guess they make use of heuristic algorithms as their graph is a very large one.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Haskell] Constraint programming - Ramsey's theorem #6
(02-09-2013, 04:17 PM)-ELM Wrote: Oh wow, it's been a while I have seen anything like this. Takes me back to when I was studying decision mathematics. The beauty of these theories is that they're purely algorithms and thus form a nice intersection between computer science and mathematics. For example (please correct me if I'm wrong) I believe Dijkstra's algorithm still has applications in route mapping for 'real' systems. Would be great to see any more work you have done on similar subjects. Deque, my hat goes off to you sir.

Thank you, Sir. I didn't expect that anyone would still comment on this one. It doesn't seem that many people here are interested in mathematics.
I am just a computer scientist, no mathematician, thus I believe you have more knowledge than me on this topic. And it is madam. Thank you for your comment. Smile
For Dijkstra's Algorithm: I honestly don't know which algorithm is implemented in map routing software today, but I guess they make use of heuristic algorithms as their graph is a very large one.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Haskell] Constraint programming - Ramsey's theorem #7
(02-09-2013, 04:17 PM)-ELM Wrote: Oh wow, it's been a while I have seen anything like this. Takes me back to when I was studying decision mathematics. The beauty of these theories is that they're purely algorithms and thus form a nice intersection between computer science and mathematics. For example (please correct me if I'm wrong) I believe Dijkstra's algorithm still has applications in route mapping for 'real' systems. Would be great to see any more work you have done on similar subjects. Deque, my hat goes off to you sir.

Thank you, Sir. I didn't expect that anyone would still comment on this one. It doesn't seem that many people here are interested in mathematics.
I am just a computer scientist, no mathematician, thus I believe you have more knowledge than me on this topic. And it is madam. Thank you for your comment. Smile
For Dijkstra's Algorithm: I honestly don't know which algorithm is implemented in map routing software today, but I guess they make use of heuristic algorithms as their graph is a very large one.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply







Users browsing this thread: 2 Guest(s)