I appreciate if anybody helps me with my question. I need to model the constraint that 4 members of two arrays follow a specific pattern given by the user in minizinc tool.
For example I need X[0],X[1],Y[0],Y[1] to take one of the following patterns:
(0,0,1,1) , (0,1,0,1) and (0,1,1,1).
I appreciate if anybody helps me figure it out.
This is easily achieved using the table constraint:
constraint table([X[0], X[1], Y[0], Y[1]], [|
0,0,1,1 |
0,1,0,1 |
0,1,1,1 |
|]);
Related
I'm currently writing my master thesis about clusterings in graphs. My prof said he wants the graph to be represented as a hash table. Because it needs less space than the adjency matrix and it is faster in checking if a edge exists between two vertices than adjency lists.
Anyway, I have a lot of problems understanding how a graph can be built with (perfect) hash functions. I know there should be two tables inside each other. The first includes every node and the second contains all the adjacent vertices. But how do I find a hash function that makes this correctly?
After I built the graph I have to assign a weight to each edge. Is it better to build a new graph or keep the old one? How can I assign the weights correctly to each edge and how do I save it?
And the last question: How fast can I do a degree query for one vertex? O(1)?
Sorry for all these questions but I read so many papers and I'm still confused.
Thank you in advance for any help!!!
Lisa
You have to ask your professor, but I would assume it is something simple.
E.g. let us say you have a triangle A,B,C then in the hash you just represent it as
A {B,C}
B {A,C}
C {A,B}
So the entry to the link A,B could be both from A and B.
What is the use of a | (a+1) .
Where i can get all the hacks regarding bit manipulation other than geeksforgeeks.
I use this concept on multiple examples but that doesn't make any pattern so that we can use it anywhere.
This turns on the rightmost zero bit in the word.
Get a copy of Hacker's Delight. Basics, page 11. A great book.
I am familiar with what choice operator ((?)) does, it takes two arguments and matches to both of them. We could define it as follows:
a?_=a
_?b=b
This can be used to introduce non-determinism between two values. However what I don't understand why we would want to do that.
What would be an example of a problem that could be solved by using (?)?
One example that is typically used to motivate non-determinism is a function that computes all permutations of a list.
insert e [] = [e]
insert e (x:xs) = (e : x : xs) ? (x : insert e xs)
perm [] = []
perm (x:xs) = insert x (perm xs)
The nice thing here is that you do not need to specify how you want to enumerate all lists, the search algorithm that underlies a logic programming language like Curry (per default it's depth-first-search) does the job for you. You merely give a specification of how a list in your result should look like.
Hopefully, you find some more realistic examples in the following papers.
New Functional Logic Design Patterns
Functional Logic Design Patterns
Edit: As I recently published work on that topic, I want to add the application of probabilistic programming. In the paper we show that using non-determinism to model probabilistic values can have advantages to list-based approaches with respect to pruning of the search space. More precisely, when we perform a query on the probabilistic values, i.e., filter a distribution based on a predicate, the non-determinism behaves less strict that an list-based approaches and can prune the search space.
Is it possible to solve this without iterating over the array?
Suppose I have an array having 4 slots, [] [] [] []
and I know 2 points [x] [x] [] [] , is it possible to have a formula that tells us the coordinates of the other two empty spots? (using a mathematical formula, (not if this then that or iterate and fin the empty spots)) I think in most cases we get lazy and instead of trying to find a real solution to problems we tend to do it the easy way, by using conditions and iterations :/
No your not given enough information. You don't know what the other two points should be. All you can tell with A[x1][x2][][] is that the last two coordinated lie on a subset that is intersected be x1 and x2
Example
Let Word be an array that give us a representation of a word in a book
Word [page][line][number of words into line]
Now if I only gave you the page of the book and the line in the page there's no way you can tell me the word you need more information
I'm doing a project where the objective is to find the less turn-cost way to send X ants from point A to point B with the restriction that only one ant at a time can stand on "in-between platforms" - don't know how to say that in English - with the exception of point A and B.
I've already looked to algorithms such as A* or the Dijkstra's but they only focus on the shortest path to get from point A to point B which, in some cases, isn't the best as you'd rather take 2 longer path and send more ants in one turn.
And this is where I'm needing you. Do you guys know such an algorithm ?
Hope I'm being clear with my question and will be looking forward to an answers.
Thanks.
EDIT : Here is an example of where the A* is not going to work :
-L-M-N-O-P-S-T-U-V-W-X-Y-Z--| Going from one letter
| | | to another costs 1 turn
H-----I-----J------K |
| | |
START--A-B-C-D-E-F-G-------END
If I have 17 ants, the best option available is sending 2 ants at a time in directions :
START-H-I-J-K-W-X-Y-Z-END
START-A-B-C-D-E-F-G-END
rather than all in START-H-I-J-K-G-END as A* would suggest as best option.
you can use A* to solve your problem you just need to adjust dynamically your map to take the position of your ants into account
You could use floodfill. What floodfill does is it traces every possible pathway and determines the best solution, but you get to define "best". For example, you can create a total time variable that tracks the time through recursion. You can make a recursive method that only returns the time variable when it reaches B, and then select the shortest value.