How to update a constant term of a constraint in Gurobi - 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...).

Related

Either-Or constraints in LPsolveAPI

I'm currently writing a MIP in LPsolveAPI in R. The program itself is straightforward, but I can't find a way to write an either-or constraint without being able to directly call a new binary variable or the binary values on the lhs. Does LPsolveAPI not support this or am I missing something obvious?
The use of new binary variables is the standard way to model either-or-constraints in lp_solve. (LpSolveAPI is based on the lp_solve solver.). So you are not missing anything obvious.
That said, one thing that might help you, depending on your constraints is the use of SOS (Special Ordered Sets). Check out the reference to SOS in lp_Solve.

What is your alternative name for ID variable in Objective-C?

Since "id" is a keyword in Objective-C what alternative name do you use for ID variable (e.g. PK field)?
I think it should be noted that the compiler can distinguish between id in the type specifier position and id in the variable name position. That is,
NSUInteger id;
id = 10;
will compile just fine (as, indeed, will id id; id = [NSNumber numberWithInt:10];). (You could also uppercase it: ID.) That said, those are all horrible ideas. Don't use them. Forget I even said that.
The style in Cocoa programming is to tend towards verbosity, so (as all the earlier answers have suggested) the best practice is probably to write it all out: identifier or dinglehopferID.
identifier, or something more specific like userID.
It often depends on context. Simply, identifier if I'm not feeling particularly creative.
I tend to use either 'identifier' — if there's really no better alternative — or something domain specific like 'programmeID' which sort of says 'this is the primary key, but only with respect to this domain'.
It's actually quite rare that you have to think in terms of primary keys within Cocoa. Core Data preserves object graphs without any nomination of primary keys, NSPredicates don't give inherently any additional weight to a field that happens to be unique per object and NSDictionarys tend to be built in an adhoc fashion.
I almost use 'guid' NSString *guid NSNumber *guid.
http://en.wikipedia.org/wiki/Globally_unique_identifier
Using id is a bad idea for me. I almost use 'uid' or 'cid' for Users and Clients respectively. I use the first letter of the model name to avoid the reserved word.

How to make an efficient check constraint for an e-mail field in Firebird

How to make an efficient check constraint for an e-mail field in Firebird (if field value not null)?
thanks, Wilfried
You could use the SIMILAR TO operator to test against regular expression pattern, something like
CHECK(emailfield SIMILAR TO '[[:ALNUM:]._%+-]+#[[:ALNUM:].-]+\.[[:ALPHA:]]+')
IMHO this kind of validation should take place in the application code, and not in the database. Anyway, the suggestion approach with a regular expression seems nice !

Long variable names

Lets say i have a variable that contains the number of search engine names in a file, what would you name it?
number_of_seach_engine_names
search_engine_name_count
num_search_engines
engines
engine_names
other name?
The first name describes what the variable contains precisely, but isn't it too long?, any advice for choosing variable names? especially how to shorten a name that is too long or what kind of abbreviations to use?
How about numEngineNames?
Choosing variable names is more art than science. You want something that doesn't take an epoch to type, but long enough to be expressive. It's a subjective balance.
Ask yourself, if someone were looking at the variable name for the first time, is it reasonably likely that person will understand its purpose?
A name is too long when there exists a shorter name that equally conveys the purpose of the variable.
I think engineCount would be fine here. The number of engine names is presumably equal to the number of engines.
See JaredPar's post.
It depends on the scope of the variable. A local variable in a short function is usually not worth a 'perfect name', just call it engine_count or something like that. Usually the meaning will be easy to spot, if not a comment might be better than a two-line variable name.
Variables of wider scope – i.e. global variables (if they are really necessary!), member variables – deserve IMHO a name that is almost self documentary. Of course looking up the original declaration is not difficult and most IDE do it automatically, but the identifier of the variable should not be meaningless (i.e. number or count).
Of course, all this depends a lot on your personal coding style and the conventions at your work place.
Depends on the context, if its is a local variable, as eg
int num = text.scan(SEARCH_ENGINE_NAME).size();
the more explicit the right-hand of the expression the shorter the name I'd pick. The rational is that we are in a limited scope of maybe 4-5 lines and can thus assume that the reader will be able to make the connection between the short name and the right-hand-side expression. If however, it is the field of a class, I'd rather be as verbose as possible.
See similar question
The primary technical imperative is to reduce complexity. Variables should be named to reduce complexity. Sometimes this results in shorter names, sometimes longer names. It usually corresponds to how difficult it is for a maintainer to understand the complexity of the code.
On one end of the spectrums, you have for loop iterators and indexes. These can have names like i or j, because they are just that common and simple. Giving them longer names would only cause more confusion.
If a variable is used frequently but represents something more complex, then you have to give it a clear name so that the user doesn't have to relearn what it means every time they use it.
On the other end of the spectrum are variables that are used very rarely. You still want to reduce confusion here, but giving it a short name is less important, because the penalty for relearning the purpose of the variable is not paid very often.
When thinking about your code, try to look at it from the perspective of someone else. This will help not only with picking names, but with keeping your code readable as a whole.
Having really long variable names will muddle up your code's readability, so you want to avoid those. But on the other end of the spectrum, you want to avoid ultra-short names or acronyms like "n" or "ne." Short, cryptic names like these will cause someone trying to read your code to tear their hair out. Usually one to two letter variables are used for small tasks like being incremented in a for loop, for example.
So what you're left with is a balance between these two extremes. "Num" is a commonly used abbreviation, and any semi-experienced programmer will know what you mean immediately. So something like "numEngines" or "numEngineNames" would work well. In addition to this, you can also put a comment in your code next to the variable the very first time it's used. This will let the reader know exactly what you're doing and helps to avoid any possible confusion.
I'd name it "search_engine_count", because it holds a count of search engines.
Use Esc+_+Esc to write:
this_is_a_long_variable = 42
Esc+_+Esc and _ are not identical characters in Mathematica. That's why you are allowed to use the former but not the latter.
If it is a local variable in a function, I would probably call it n, or perhaps ne. Most functions only contain two or three variables, so a long name is unnecessary.

Can we use "if else" in "Check" constraint in sql server

Can i use if else under a check constraint.
Can i use check constraint using a variable
need xplanation with eg.
Your question is a bit vague. What are you trying to do with the IF...ELSE? Check constraints aren't processed code, they're part of the table definition - there is no control flow and no variables. You can use a user-defined function in check constraints, which may be what you're after, but it's hard to tell from your question.
You cannot use IF/ELSE, but you can use inline conditionals: CASE WHEN