Suppose that you have a car that is required to visit cities A, B, C, D and E in the shortest possible time or distance. But there is order of precedence in which these cities can be visited. For e.g., B must be visited first before you visit “A,” and “E” must be visited first before you can visit “C.” So all of the following solutions are valid:
Car -> B, D, E, A, C
Or
Car -> D, E, B, A, C
Or
Car -> E, B, A, D, C
Following routes will be invalid:
Car -> A, B, D, E, C (Constraint violated since B must be visited first before you can visit A)
Or
Car -> B, D, A, C, E (Constraint violated since E must be visited first before you can visit C)
In Optaplanner, is there any way to enforce such constraints? I think this has to be done while forming a chain. The default chain might have to be manually revisited to enforce such a constraint. But I don’t know how. Any pointers will be greatly appreciated.
Vikas
Introduce a shadow variable that keeps the chainIndex in a chain of a vehicles.
For example: Vehicle A starts in Brussels then goes to Paris then to London. Vehicle B starts in Brussels then goes to Berlin and then to Prague. Then it works like this:
Paris's anchor is A and its chainIndex is 1.
London's anchor is A and its chainIndex is 2.
Berlin's anchor is B and its chainIndex is 1.
Prague's anchor is B and its chainIndex is 2.
Adding your constraint by using that chainIndex and the anchor is then trivial.
Related
z=(-1/(4*(-u+L)))(4*p^2*b^2*d-3*g*c*p^2)
given fixed values of u, L, and c, I would like to Maximiz Z(p, b) by finding best p and b, subject to
1-(2* d)/(p*(sqrt(g)+1))<=b<=1
0<=d<=L
Min(c,L)<=p<=u
1<=g<=4
Consider the following set of functional dependencies on the relation schema R = (A, B, C, D, E). Decompose the relation into a collection of relation schemas in 4NF. Provide detailed information of the decomposition process.
AB →→ C
B → D
A → E
If you start from the top with AB →→ C, doesn't that fit 4nf and you are done?
I've some variables, Lets say a, b, c, d. All belongs to a fixed interval [0, e]
Now i've some relations between them like
a > b
a > c
b > d
Something like this; I want to make a function which print all the possible cases for this.
Example:
a b c d
a c b d
a b d c
a c b d
In essence, what you have is a directed acyclic graph.
A relatively simple approach is to store, for each variable, a set of the variables that must precede them. (In your example, this storage would map b to {a}, c to {a}, and d to {b}.) You can then write a recursive function that generates all valid tails consisting of a subset of these variables (in your case, for example, the subset {c,d} produces two valid tails: [c,d] and [d,c]). This recursive function examines each variable in the subset and determines whether its prerequisites are already met. (For example, since b maps to {a}, any subset including both a and b cannot produce a tail that begins with b.) If so, then it can recursively call itself on the subset excluding that variable.
There are some optimizations you can then perform, if desired. For example, you can use dynamic programming to avoid repeatedly re-computing the set of valid tails for the same subset.
Hi recently i appeared in an aptitude,there was a problem that i realy cant understand please provide some idea, how to solve it.(and sorry to for poor English.)
(Question)-> Three candidates, Amar, Birendra and Chanchal stand for the local election. Opinion polls are
conducted and show that fraction a of the voters prefer Amar to Birendra, fraction b prefer Birendra to
Chanchal and fraction c prefer Chanchal to Amar. Which of the following is impossible?
(a) (a, b, c) = (0.51, 0.51, 0.51);
(b) (a, b, c) = (0.61, 0.71, 0.67);
(c) (a, b, c) = (0.68, 0.68, 0.68);
(d) (a, b, c) = (0.49, 0.49, 0.49);
(e) None of the above.
If you tried to list of possible preferences people can have
are either
ABC (means you prefer A to B, prefer B to C and therefore also prefer A to C)
ACB
BAC
BCA
CAB
CBA
in this case you'll find that each fraction of the population represents:
a=ABC+ACB+CAB
b=ABC+BAC+BCA
c=BCA+CAB+CBA
therefore a+b+c = 2(ABC+BCA+CAB)+ACB+BAC+CBA
as you notice not all groups within the population are repeated. we can therefore assume than (a+b+c) can never be more than twice the population since each member of the population is represented twice at the most.
out of the options C is the one where the sum is more than 2. and is therefore the impossible value.
Here's a few questions I had on a quiz in a class and just want to verify their correctness.
Grammar:
S -> ABC
A -> df | epsilon
B -> f | epsilon
C -> g | epsilon
1.) The Follow set of B contains g and epsilon (T/F)? Ans: F.
There is no epsilon in the Follow sets, correct? (Only $ aka end of input)
2.) The First set of S contains d, f, g, and epsilon (T/F)? Ans: T.
I said false for this because I thought First(S) = First(A), which g is not a part of. Who is correct?
You are correct. If epsilon is involved, it will be accounted for in the First set, not the Follow set. If it's possible for the production to end the string, then $ goes in the Follow set, not epsilon.
The quiz is correct. The production S can indeed start with any of d, f, and g, and it can also be started by the empty string. Consider the input string g. It matches S, right? A is satisfied by the empty string, B is satisfied by the empty string, and C is satisfied by g. Since A, B, and C are all satisfied, S is satisfied. The first character consumed by S is g, so g must be in First(S).