NetLogo: How to change shape of a turtle if condition is true? - if-statement

I want to make 2 turtles(a male and a female) get married. I have 2 different shapes for males and females in my simulation.
If a female meets a male on the same patch, they get married. When they do, I want to bundle them as one unit (i.e. I want to delete one of the turtles, and change the other to a third shape indicating a married couple).
How can I do this. I am already lost at the "meeting" stage.
What I have:
if any? other turtle-here with [?????]
Pseudocode:
if female on_same_patch_as_male:
change her marital-status to married
Remove [one of the two turtles]
change the shape of the remaining turtle to "married-couple-icon"
Any help is appreciated

Related

Count occurances in multiple filtered rows

I need a little help since im new to PowerBI. I have a data set which says what have been eaten in a specific day. At the end there are columns which show if the day before the overall feeling was better (so in this specific day it got worse). I got up to 30 Ingredients and 5 days before. The "1" in e.g. Day2 means its TRUE for condition "2 days before it got worse"
The data looks like this:
Data set example
Now, I want to retrieve and add up all ingredients, which has been eaten at "Day1", "Day2" and so on, so I can see which food is maybe causing problems because it should appear more often in the days before or at least appear in every case there. How do I achieve this?
For example I can see then, that on Day2 overy often Ingredient "Apple" appears, so there could be an assumption that Chicken meat is not good for this person.
I tried to pivot the table, as well as disconnect the "DayX" into another table and make relationship between them, but nothing adds up the things in the way I want it to.

How do I know if there are any more solutions?

I have done the Einstein's Riddle exercise with linear programming. I implemented this solutions in Gusek. How can i tell if there is more than one solution?
Einsten's riddle:
There are 5 houses in five different colors.
In each house lives a person with a different nationality.
These five owners drink a certain type of beverage, smoke a certain brand of cigar and keep a certain pet.
No owners have the same pet, smoke the same brand of cigar or drink the same beverage.
Constaints:
the Brit lives in the red house
the Swede keeps dogs as pets
the Dane drinks tea
the green house is on the left of the white house
the green house's owner drinks coffee
the person who smokes Pall Mall rears birds
the owner of the yellow house smokes Dunhill
the man living in the center house drinks milk
the Norwegian lives in the first house
the man who smokes blends lives next to the one who keeps cats
the man who keeps horses lives next to the man who smokes Dunhill
the owner who smokes BlueMaster drinks beer
the German smokes Prince
the Norwegian lives next to the blue house
the man who smokes blend has a neighbor who drinks water
Can I tell which constraints are redundant?
Thank you for your help
Your decisions/solution will be in the form of binary or integer varibles.
If they are binary, add in a new constraint like the one below:
(Y are all the binaries which were 1 and `Y are binaries which were 0.)
sum(Y) + sum(i-Y) != |Y|+|Y|
Keep repeating this till you get an infeasible model. This can be extended to the integer case too.
As for redundancy, you have to manually try removing them and see if the solution changes. However, in terms of reduncancy, you might have cases where constraint A and B are redundant OR constraint C is redundant. You could have multiple sets of potential redundant constraints depending on which you eliminate.

Hadoop Map Reduce - Number of Reducer

I have use case that has data of employee of a company of different age group.
I need to find highest salary of male and female employee of three age group category.
for detail pls go to below link -
http://www.myhadoopexamples.com/2014/03/01/hadoop-mapreduce-example-with-partitioner/
My question is - Here we have only two key emited by mapper i.e male and female.
and we have set 3 reducer in driver class thus 3 partition will be created.
There could be two below things -
3 reducer will be running for each 3 partition which inturn find out
max female and male salary in each partioner. and gives expected result as shown in above link.
Only reducer will be running actually , one of male and one for female and do the calculation
If you want to know the real num of reducers, you'd better run it on cluster.
As said in Number of reducer in map reduce, it will launch 3 reducers and 1 reducer will process no data. If you want to use all three reducers, you may change the Partioner class, like partitioning data by the age group

Django ORM how to maintain non-automatic counter integrity on a large table?

Lets assume I have the following table 'book' (with tens of millions of rows):
id shelf position (on shelf)
1 2 3
2 1 1
3 1 2
4 2 2
5 2 1
... ... ...
40000000 1 2543355
And I need to move book 2 to another shelf or totally remove it.
Is there a good way to close the gap in positions that will open because of it?
I know there is this way to do it, but it will be really bad for performance, won't it?
Book.objects.filter(shelf=self.shelf, position__gt=self.position).update(position=F('position')-1)
I am thinking about changing maximum position on the shelf to moving/deleting position.
Is there a good way to do it with Django ORM?
What you want to do is very similar to a leaderboard implementation in rdbms. This is a really good read for doing that.
Essentially, what you want to do (in sql) is:
UPDATE book SET position = position - 1 WHERE shelf = X and position > Y
Where X is the shelf you moved the book from, and Y is its former position on that shelf. SQL syntax may vary.
In that article there are also examples of doing an insert of position into an existing shelf where positions must increase to make room for the newly inserted book. The article goes on to explain how to best do these in batches as moving one at a time, and then updating N records per move can be quite costly especially if you are repositioning the same books in the same shelf repeatedly.
For example, if you have 100 books on shelf 1, and you move two of them in positions [22, 56], then the optimal solution would move each book from 23-55 by one position, and each book from position 56-100 by two positions. The naive approach would move everything from 23-100 by one position. Then move everything from 56-100 by one position again.
A good way (performance-wise) to close the gap (book2 moved from shelf=1, position=1) will be this (move the last book on shelf to the opened position):
Book.objects.filter(shelf=1).order_by('-position')[0].update(position=1)
An index on (shelf, position) is also needed to maintain performance.
(Found this answer in a related question)

Choosing all possible options from List in Prolog

So I have to write different procedures that will help me solve the farmer-wolf-goat-cabbage-fertilizer puzzle. For those of you that don't know it, it involves a farmer having to cross from the North bank of a river to the South bank with all the other objects. A bank is rendered safe in 3 situations: the farmer is present OR, the wolf is not left with the goat OR, the goat is not left behind with the cabbage. For the purpose of the exercise, the variables will be [f,b,g,w,c].
The procedure (choose(Bank, Items)) I am stuck at involves finding a list of 1 or 2 elements (always including the farmer - f), that could be part of a transport from a Bank without leaving it unsafe.
If one does choose([g,f,b], Items), the possible returned values for Items can be [f], [f,g], [f,b]. However, if we do choose([g,f,c], Items), the only possible values returned are [f,c] or [f,g], since the goat and cabbage cannot be left behind together.
Thus, could anyone please give me a hint how to get all possible options for Items but in lists no longer than 2 items?
I can't test right now but I guess that you could write something like :
choose(Bank, [f, Other]) :-
select(f, Bank, Rest),
select(Other, Rest, LeftBehind),
safe(LeftBehind).
choose(Bank, [f]) :-
select(f, Bank, LeftBehind),
safe(LeftBehind).