Constraining more than one IntVarArray - or-tools

I'm working with several IntVarArray-s in a model in a way that there are cross-dependencies between their elements. Is this the correct way to use them as parameter for the MakePhase method?
var nr = 10;
var fLoc = s.MakeIntVarArray(nr, 0, 1);
var gLoc = s.MakeIntVarArray(nr, 0, 1);
// ... create other arrays
// ... constrain the arrays
// collect them
var decisions = new IntVarVector();
decisions.AddRange(fLoc);
decisions.AddRange(gLoc
//... add other arrays to decisions
// call MakePhase
solver.MakePhase(decisions, ...);

Yes this works.
Please make sure that either the order is the right one, or choose a variable selection strategy that is dynamic like CHOOSE_MIN_SIZE_LOWEST_MIN.

Related

How to shuffling the order of a list from snapshot.docs from Stream in firestore [duplicate]

I'm looking every where on the web (dart website, stackoverflow, forums, etc), and I can't find my answer.
So there is my problem: I need to write a function, that print a random sort of a list, witch is provided as an argument. : In dart as well.
I try with maps, with Sets, with list ... I try the method with assert, with sort, I look at random method with Math on dart librabry ... nothing can do what I wana do.
Can some one help me with this?
Here some draft:
var element03 = query('#exercice03');
var uneliste03 = {'01':'Jean', '02':'Maximilien', '03':'Brigitte', '04':'Sonia', '05':'Jean-Pierre', '06':'Sandra'};
var alluneliste03 = new Map.from(uneliste03);
assert(uneliste03 != alluneliste03);
print(alluneliste03);
var ingredients = new Set();
ingredients.addAll(['Jean', 'Maximilien', 'Brigitte', 'Sonia', 'Jean-Pierre', 'Sandra']);
var alluneliste03 = new Map.from(ingredients);
assert(ingredients != alluneliste03);
//assert(ingredients.length == 4);
print(ingredients);
var fruits = <String>['bananas', 'apples', 'oranges'];
fruits.sort();
print(fruits);
There is a shuffle method in the List class. The methods shuffles the list in place. You can call it without an argument or provide a random number generator instance:
var list = ['a', 'b', 'c', 'd'];
list.shuffle();
print('$list');
The collection package comes with a shuffle function/extension that also supports specifying a sub range to shuffle:
void shuffle (
List list,
[int start = 0,
int end]
)
Here is a basic shuffle function. Note that the resulting shuffle is not cryptographically strong. It uses Dart's Random class, which produces pseudorandom data not suitable for cryptographic use.
import 'dart:math';
List shuffle(List items) {
var random = new Random();
// Go through all elements.
for (var i = items.length - 1; i > 0; i--) {
// Pick a pseudorandom number according to the list length
var n = random.nextInt(i + 1);
var temp = items[i];
items[i] = items[n];
items[n] = temp;
}
return items;
}
main() {
var items = ['foo', 'bar', 'baz', 'qux'];
print(shuffle(items));
}
You can use shuffle() with 2 dots like Vinoth Vino said.
List cities = ["Ankara","London","Paris"];
List mixed = cities..shuffle();
print(mixed);
// [London, Paris, Ankara]

Change color for specific functions

I'm using assertions in my code, here is the example:
this.getNewLinkId = function() {
var newLinkId = this.links.length + 1;
console.assert(this.getLink(newLinkId).length === 0, 'Generated ID is already present within links!');
return newLinkId;
};
But because of them the code may be slightly harder to read. Is there any way to specify the syntax highlight for assert functions? Make their color like that of comments, for example?
As far as I know, you can't do that in NB. Maybe a strategic newline might help you though?
e.g.
this.getNewLinkId = function() {
var newLinkId = this.links.length + 1;
console.assert(this.getLink(newLinkId).length === 0,
'Generated ID is already present within links!');
return newLinkId;
};

Filter getElementsByTagName list by option values

I'm using getElementsByTagName to return all the select lists on a page - is it possible to then filter these based upon an option value, ie of the first or second item in the list?
The reason is that for reasons I won't go into here there are a block of select lists with number values (1,2,3,4,5 etc) and others which have text values (Blue and Black, Red and Black etc) and I only want the scripting I have to run on the ones with numerical values. I can't add a class to them which would more easily let me do this however I can be certain that the first option value in the list will be "1".
Therefore is there a way to filter the returned list of selects on the page by only those whose first option value is "1"?
I am pretty sure that there is a better solution, but for the moment you can try something like:
var allSelect = document.getElementsByTagName("select");
var result = filterBy(allSelect, 0/*0 == The first option*/, "1"/* 1 == the value of the first option*/);
function filterBy(allSelect, index, theValue) {
var result = [];
for (var i = 0; i < allSelect.length; i++) {
if(allSelect[i].options[index].value == theValue ) {
result.push(allSelect[i]);
}
}
return result;
}
I managed to get this working by wrapping a simple IF statement around the action to be performed (in this case, disabling options) as follows:
inputs = document.getElementsByTagName('select');
for (i = 0; i < inputs.length; i++) {
if (inputs[i].options[1].text == 1) {
// perform action required
}
}
No doubt there is a slicker or more economic way to do this but the main thing is it works for me.

jquery same selector for multiple contexts

I want wrote a elegant solution that select a same tag by searching in
a list of different contexts
//i have this not editable code
var c1$ = $('#context1'),
c2$ = $('#context2'),
c3$ = $('#context3');
//I want to improve the code and 'only from here on
var selector = 'a.select';
c1$.find(selector).css('color','red');
c3$.find(selector).css('color','red');
I'm searching a solution for arbitrary number of contexts
You can use $.add() to build up your context, and then use it as a single jQuery object within the context parameter of your selector:
var $foo = $("#foo"),
$bar = $("#bar");
var $context = $foo.add($bar);
$("a.select", $context).css("color", "red");
Why don't load a list of context, and then do a foreach to find the 'a.select' in each of the context?.
my desperate not elegant solution
var contexts = [$('#context1'),$('#context2'),$('#context3')];
//list of contexts in single variable(arbitrary number!)
var selector = 'a.select';
//same selector for all variable contexts
var cons$ = $([]);
//empty temporary selector
for(i in contexts)
cons$ = cons$.add(contexts[i]);
var allmatches$ = cons$.find(selector);
//here processing allmatches$
allmatches$.css("color", "red");
//now apply css in one step

In linq-to-entities, how to return objects with a filtered list of children?

I have the following model
The first step is to select all the ProductionBlock with
var blocks = context.ProductionBlocks;
How can I combine the ProductionLog that has no end time with the ProductionBlock?
I tried to do it using a reverse lookup like
var blocks = context
.ProductionLogs
.Include("FK_ProductionLog_ProductionBlock")
.Where(log => log.EndTime == null).Select(log => log.ProductionBlock)
.Union(context.ProductionBlocks);
But the blocks don't contains any ProductionLogs. How can I achieve that?
Let me know if i am off base, but you would want.
var logs = (
from pl in context.ProductionLogs.Include("ProductionBlock")
where pl.EndTime == null
select pl);
You would then have a list of logs and blocks.
var blocks = logs.SelectMany(x=>x.ProductionBlock)