How do I add a name for a constraint in Pyomo? - linear-programming

I want to add names to my constraints so that it's easier to read the .lp / .gams files.
EDIT: Sorry if I hadn't mentioned, but I want to do this when a constraint list is initialized and constraints are added to it. Pyomo documentation has it only for normal constraints.
I was using PuLP before and was able to just add a string in the end of a constraint. Not sure how to do it with Pyomo. Documentation does not show it anywhere.

This question was answered on the Pyomo forum: https://groups.google.com/forum/?nomobile=true#!topic/pyomo-forum/5DgnivI1JRY

Related

Django doesn't group by if I omit order_by() clause

I was trying to find an answer for this question in documentation but I unfortunately did not succeed.
In documentation it states that if I want to group my objects and Count them I should use the following:
MyObject.objects.values('field_to_group_by').annotate(Count('field_to_count'))
However it doesn't work. But when I add simple order_by it does:
MyObject.objects.values('field_to_group_by').annotate(Count('field_to_count')).order_by()
Any idea why is that? They didn't mention that in documentation.

Django/DRF filtering

I filter my list of Product models by title field. For example, I want to find this title = 'Happy cake'. And if I type
Case 1. 'happy cake',
Case 2. 'hapy cake', happi kake'
it should return me 'Happy cake'.As I know icontains helps me with case 1. How can I get that?May be some sort of technologies should be added or django itself has appropriate solution?
You can try using the lookup __in
Model.objects.filter(title__in=['happy cake', 'happi kake'])
You can put as many test cases you want in the list.
You can do this other way.
If you are sure about the start ha here
Happy Cake
Hapy cake
happi kake
Product.objects.filter(title__startswith='ha')
This kind of question is hard to solve by just using Django inbuild search system. So this is one way to solve this question. ElasticSearch. It has fuzzy search and indexing. Cool thing to deal with tough tasks). I pushed to git some starting code. It doesn't solve this question fully, but with some workaround that goal can be achieved.

How to get variables of a constraint in Pyomo

In Pyomo, how can I get a list of the variables appearing in a constraint?
I combed through the code in Github, but could not a find any suitable method or attribute for that purpose.
I found the answer myself: model.con1.body._args gets you the desired list.

GATE - How to create a new annotation SET?

I am starting to learn GATE. I created an annotation with features but I would like to put it in a new annotation set.
Can someone please tell me how to do it with JAPE?
Thanks
I found the answer to my question in http://sourceforge.net/p/gate/mailman/message/5348688/ and http://osdir.com/ml/ai.gate.general/2005-04/msg00052.html.
They said that a JAPE rule can't refer to more than one annotation set. These annotation sets are defined in the PR runtime parameters (outputASName, inputASName).
--> So I guess that if I want my annotation to belong to a "Key" annotation set, I should put "Key" in outputASName of my Jape transducer.
Thanks for your help Ian =)

Mongoid 4 finding embedded documents by ID

I have a project that is my first serious dive into Mongoid.
I saw a tip to use the following command:
Parent.where('childrens._id' => Moped::BSON::ObjectId(params[:id])).first
But this doesn't work. Error message was:
NameError: uninitialized constant Moped::BSON
I found that BSON is no longer included, so I added it to my Gemfile, as well as Moped. Then, I did another fix I found (placing Moped::BSON=BSON in application.rb).
This still didn't work, but the error changed to:
NoMethodError: undefined method `ObjectId' for BSON:Module
So I am assuming that this method got deprecated or something. Does anyone have any other tips?
Just to be clear, I am finding myself in the situation where I want to sort embedded documents using jquery-sortable. This requires me to update them in the database, but the serialize from that doesn't include the parent document in the hash. So I figured I'd try to get it on the back end using an ID from the embedded document. That is why I need it.
Thanks again for any help you can provide.
Try simply:
Parent.where('childrens._id' => params[:id]).first
I have solved the question though this won't be of much help to people in the future. The requirements have changed and now I am using human-readable strings as IDs to assist in friendly URLs and some other stuff.
Therefore, I don't have any issues with ObjectIds. Cortex's solution should (from what I have read) work for dealing with ObjectIds but I cannot verify it now.