Gurobi add constraint which two variables cant be zero at the same time - gurobi

I'm currently using Gurobi in python and trying to add a constraint that the variable will not equal to 0 at the same time, for example, a != 0 or b != 0. But I can't find a proper function to add this constraint.
Anyone have idea about this?

Related

Pandas Value Counts With Constraint For More Than One Occurance

Working with the Wine Review Data from Kaggle here. I am able to return the number of occurrences by variety using value_counts()
However, I am trying to find a quick way to limit the results to varieties and their counts where there is more than one occurrence.
Trying df.loc[df['variety'].value_counts()>1].value_counts()
and df['variety'].loc[df['variety'].value_counts()>1].value_counts()
both return errors.
The results can be turned into a DataFrame and the constraint added there, but something tells me that there is a way more elegant way to achieve this.
#wen ansered this in the comments.
df['variety'].value_counts().loc[lambda x : x>1]

How to update a constant term of a constraint in Gurobi

I am facing a problem where I must call the Gurobi engine iteratively. Between runs, I have to update the constant term in some of the constraints. I check the manual book in which I find GRBModel::chgCoeff() could be used to change the coefficient of variables in the constraint but there is no function related to changing the constant term. Any idea to do that? Thank you!
I think that you have to set the RHS attribute of the Linear Constraint object. So, if constr is your constraint, something like
constr.Set(GRB.DoubleAttr.RHS, 329);
(this is C#, I guess you use C++, so the case of some of the letters may be different...).

Default value for missing field in document for elasticsearch statistical facet

I am using a statistical facet (#see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-statistical-facet.html) to perform an aggregation on a few fields across the documents in my Elastic Search index.
I was wondering if anyone knew if the API provided a means to provide a default value if a particular field does not exist. For example, if a field does not exist use 0 (zero) as that fields value. By default it seems to give a null pointer exception when the aggregation is taking place.
My initial thoughts are to utilize a script field to test if the aggregation field is null and perform the default 0 logic there.
As you stated in your question, you could try a script field as defined here: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-statistical-facet.html#_script_field_2
For example: "script" : "_source.place == null ? null : 0"
I'll admit that I have not tried this on a statistical facet, but I have used a similar script on a terms stats facet and it worked fine.

Make column value less than or equal than current date

I need to make sure the entry of one of my columns lets call it CreationDate is =< current date.
After failing trying to use this
CHECK ( CreationDate =< GETDATE())
For the reasons mentioned in this post:
CHECK constraint on date of birth?
I'm wondering how would I write a Trigger for SQL Server that will check if the date im trying to insert/update is =< currentDate
I have never used triggers before, I came out with this, but I'm not sure if it works, or how will it be called.
I'm trying to make the trigger return an error so that the programmer is forced to check or fix this.
CREATE TRIGGER CheckValidDateTrigger
ON Reports
INSTEAD OF
UPDATE
AS
DECLARE #ReportCloseDate DateTime;
IF (#ReportCloseDate > GETDATE())
BEGIN
RAISERROR ('Error, the date your trying to save cannot be higher or newer that the current date. The date must be in the past or be the current date', -- Message text.
16, -- Severity.
1 -- State.
);
END;
Can you guys help me out a little?
The documentation says any expression that evaluates to TRUE or FALSE:
CHECK constraints enforce domain integrity by limiting the values that
are accepted by one or more columns. You can create a CHECK constraint
with any logical (Boolean) expression that returns TRUE or FALSE based
on the logical operators.
There is not a restriction (as far as I've found) on non-deterministic functions (that is, on functions where the same call may return different values at different times).
The example that you point to is tagged Oracle. It also gives an alternative solution which is to add a column whose default value is getdate() and to check against that.
So, your check constraint as intended should work.

Having trouble setting a computed column as not Null

I'm having problems setting a computed column as not null.
What I want to achieve is C001,C002..., etc. and at the same time set it as not null.
I have read on a forum that this can be achieved by using the default value 0 for NULL values.
E.g., ISNULL(Price + Taxes, 0)
I have tried to apply to this formula:
('C'+right('000'+CONVERT([varchar](3),[ID],(0)),(3)))
But it didn't seem to work. Can anyone tell me what am I missing?
ALTER CreditCard accountNo AS ISNULL('C'+right('000'+CONVERT([varchar](3),[idCreditCard],(0)),(3)),0)
I've finally found the solution to my problem!
The correct query should be:
ALTER TABLE CreditCard ADD accountNo AS ISNULL('C'+right('000'+CONVERT([varchar](3),[idCreditCard],(0)),(3)),0)
Thanks for the help guys!
If this relates to SQL Server, you might be interested in this from MSDN.
'NOT NULL can be specified for computed columns only if PERSISTED is also specified.'
http://msdn.microsoft.com/en-us/library/ms190273.aspx
... but after trying to reverse-engineering the question from the answer, I think that 'keenlearner wanted only to ensure that there was never a null value in the column without having the constraint.