Randomisation - Partial Incomplete Block Design - block

I'm looking to replicate this randomisation in R studio.
Key features:
A and B are the primary comparison and must have 2 by 2 cross over design (i.e., occur togeather in each sequence)
The incomplete block design should include C D E and F - comparisons of interest are C vs D and E vs F. These comparisons need to occur the same number of times within the whole design, and one comparison must occur in each sequence
C D E F need to be balanced so that they occur the same number of times in a sequence
C D E F need to be balanced so that occurr the same number of times across periods
Any help would be greatly appreciated.
Many thanks.
The code I tried below is just for the incomplete block design C,D,E,F but I can't get it to balance across periods.
library(crossdes)
out=find.BIB(4,20,3, iter=1)#each dosed 6 times achieving first order balance
out
isGYD(out)
I had then planned to join on the A and B rand.

Related

Creating a LP Constraint

Below I have summarized how my outputVar should behave with DecisionVar:
Entity EntityValue DecisionVar1 OutputVar1 DecisionVar2 OutputVar2
A 5 1 5(base) 1 5(base)
B 2 1 5(=prev) 1 5(=prev)
C 3 1 5(=prev) 2 5(3+2)
D 4 2 9(4+3+2) 2 5(=prev)
Scenario 1:
Since A, B, C are all allotted 1, each outputVar is set to base(=5), while D is the sum of the rest of the values.
Scenario 2:
Since A and B are allotted 1. outputVar is set to base same as A, while for C, the value is the sum of the previous remaining values and since D is set same as C, its outputVar is set same as C.
Context: If certain entities are grouped together, we are trying to constraint the time allotted to process those entities. For group of entities(except the base) the time remaining is the time from the first of the previous group to the first of the current group.
One of the easier ways to do this is to redefine your problem in terms of the groups of entities and model it as a set partitioning/ set covering problem.

Reordering rows in sql database - idea

I was thinking about simple reordering rows in relational database's table.
I would like to avoid method described here:
How can I reorder rows in sql database
My simple idea was to use as ListOrder column of type double-precision 64-bit IEEE 754 floating point.
At inserting a row between two existing rows we calculate listOrder value as average of these sibling elements.
Example:
1. Starting state:
value, listOrder
a 1
b 2
c 3
d 4
e 5
f 6
2. Moving "e" two rows up
One simple sql update on e-row: update mytable set listorder=2.5 where value='e'
value, listOrder
a 1
b 2
e 2.5
c 3
d 4
f 6
3. Moving "a" one position down
value, listOrder
b 2
a 2.25
e 2.5
c 3
d 4
f 6
I have a question. How many insertions can I perform (in the edge situation) to have properly ordered list.
For the 64 bit integer there is less than 64 insertions in the same place.
Is floating point types allows to more insertions?
There are other problems with described approach?
Do you see any patches/adjustments to make this idea safe and usable in applications?
This is similar to a lexical order, which can also be done with varchar columns:
A
B
C
D
E
F
becomes
A
B
BM
C
D
F
becomes
B
BF
BM
C
D
F
I prefer the two step process, where you update every row in the table after the one you move to be one larger. Sql is efficient about this, where updating the rows following a change is not as bad as it seems. You preserve something that's more human readable, the storage size for your ordinal value scales in a linear rather with your data size, and you don't risk coming to a point where you don't have enough precision to put an item in between two values

finding largest number of candidate keys that a relation has?

I am trying to solve this question which has to do with candidate keys in a relation.
This is the question:
Consider table R with attributes A, B, C, D, and E. What is the largest number of
candidate keys that R could simultaneously have?
the answer is 10 but i have no clue how it was done, nor how does the word simultaneously plays into effect when calculating the answer.
Sets that are not subsets of other sets.
For example {A-B} and {A,B,C} can't be candidates keys simultaneously, because {A,B} is a subset of {A,B,C}.
Combinations of 2 attributes or 3 attributes generates the maximum number of simultaneous candidates keys.
See how the 3 attributes sets are actually complements of the 2 attributes sets, e.g. {C,D,E} is the complement of {A,B}.
2 3
attributes attributes
sets sets
1. {A,B} - {C,D,E}
2. {A,C} - {B,D,E}
3. {A,D} - {B,C,E}
4. {A,E} - {B,C,D}
-
5. {B,C} - {A,D,E}
6. {B,D} - {A,C,E}
7. {B,E} - {A,C,D}
-
8. {C,D} - {A,B,E}
9. {C,E} - {A,B,D}
-
10. {D,E} - {A,B,C}
If I would take sets of a single attribute I would have only 4 options
{A},{B},{C},{D}
Any set with more than 1 element will contain one of the above and therefore will not be qualified.
If I would take sets of 4 attributes I would have only 4 options
{A,B,C,D},{A,B,C,E},{A,B,D,E},{B,C,D,E}
Any set with more than 4 element will contain one of the above and therefore will not be qualified.
Any set with less than 4 element will be contained by one of the above and therefore will not be qualified.
etc.
For 5 keys, it is probably best to do this by brute force. Understanding the ideas is more important than the calculation (DuDu/David gives a good example of 10 candidate keys, showing that a set of 10 keys is possible so the maximum is at least this large).
What is the idea? A candidate key is a combination of attributes that is unique. So, if A is unique, then A with any other column is also unique. One set of candidate keys is simply:
A
B
C
D
E
If each of these are unique, then any combination of keys is going to contain at least one of these attributes and the combination will also be unique. Hence, the uniqueness of these five would imply the uniqueness of any other combination.
5 is not the largest number of candidate keys with this property.
It gets a bit more complicated. If {A, B, C, D, E} is unique (and no subset is a candidate key), then there is exactly 1 candidate key. Rearranging the columns doesn't change the set (sets are unordered).
One thing we might postulate is that the biggest set of candidate keys has keys all of the same length. This is in fact true. Why? Well, if we have a set of keys that are of different lengths, we can lengthen the shorter ones by adding arbitrary attributes and still have a maximal set.
So, you only need to consider subsets of 1, 2, 3, 4, and 5 keys, exactly. When you work it out, you will find that the maximum numbers are:
5 10 10 5 1
You can add a "1" to the beginning and you may recognize the pattern. This is a row from Pascal's Triangle. This observation (well, and the related proof) actually makes it easy to determine the maximum value for any given n.
Incidentally, the sets of length 3 are:
A B C
A B D
A B E
A C D
A C E
A D E
B C D
B C E
B D E
C D E

Crystal Reports changing sorting with custom logic

I need to sort a demand pick list report by BIN_id, but in an odd logic that I am not sure how to handle through crystal reports. So, bins are going to be [A-J][01-06][01-06], so for example D0306 would be one of the bin numbers.
The warehouse is set up as so (imagine the middle line of this table is where the warehouse workers will be walking).below is the format
A B
C D
E F
G H
What we want them to do is start with the "A" side of the bins, go all they way down to the farthest letter they need (up to G), switch over to the opposite side of the bin they stopped on (so if they only went down to E, they would end up at F and go up and pick from F through B). What I need to do with crystal reports is get BIN ID'S to sort like the examples below:
EDIT: A batch of orders is going to have BIN_ids that can possibly start with A-G. For example a batch of orders might have bins A0102, B0304, G0304, G0106, E0101, C0106, C0205, C0404, D0106, D0202. With this order I would want is sorted as such:
A0102, C0106, C0205, C0404, E0101, G0304, G0106, D0106, D0202, B0304
EDIT: More examples
if only A and B bins exist in the batch of orders:
A bins then B bins
if A bins through F bins exists in the batch:
A then C then E then F then D then B
if C,E,G,D exist in the batch of orders:
C then E then G then D
And so on and so on. Basically we want warehouse workers to make a U shape while they are picking through the warehouse. Start at A, go down to G, switch over to H and go up to B. This logic isn't complicated, I just have no idea how to go about doing it in Crystal...
Thanks your you help everyone, let me know if something doesn't make sense.
Your explanation is very confusing!!!!
After reading multiple times I understood you want to sort the report in the way you wish to and my solution will be according to this.
You need to manually apply sorting on the filed that is obtained from database so the solution should be:
Group the report according to the required field now when insert group window is appeared then go to tab "Group in Specefied order" and at that tab set the way you want to view the report.
If I am totally out of your problem.. Explain clearly will try to help.

Algorithm - combine multiple lists, resulting in unique list and retaining order

I want to combine multiple lists of items into a single list, retaining the overall order requirements. i.e.:
1: A C E
2: D E
3: B A D
result: B A C D E
above, starting with list 1, we have ACE, we then know that D must come before E, and from list 3, we know that B must come before A, and D must come after B and A.
If there are conflicting orderings, the first ordering should be used. i.e.
1: A C E
2: B D E
3: F D B
result: A C F B D E
3 conflicts with 2 (B D vs D B), therefore requirements for 2 will be used.
If ordering requirements mean an item must come before or after another, it doesn't matter if it comes immediately before or after, or at the start or end of the list, as long as overall ordering is maintained.
This is being developed using VB.Net, so a LINQy solution (or any .Net solution) would be nice - otherwise pointers for an approach would be good.
Edit: Edited to make example 2 make sense (a last minute change had made it invalid)
The keyword you are probably interested in is "Topological sorting". The solution based on that would look as follows:
Create an empty directed graph.
Process sequences in order, for each two consecutive elements X,Y in a sequence add an edge X->Y to the graph, unless this would form a cycle.
Perform a topological sort on the vertices of the graph. The resulting sequence should satisfy your requirements.