Gurobi Equivalent of `CPX_PARAM_ALL_MIN` and `CPX_PARAM_ALL_MAX` - gurobi

I am trying to find if there are any equivalents of CPX_PARAM_ALL_MIN and CPX_PARAM_ALL_MAX.
I am trying to port some code from CPLEX to GuRoBi
and there is some code like this
for (int i = CPX_PARAM_ALL_MIN; i <= CPX_PARAM_ALL_MAX; ++i)
{
stat = CPXgetparamname(env, i, name);
}
while I found out that CPXgetparamname equivalent is GRBgetparamname, I am unable to find the equivalents of CPX_PARAM_ALL_MIN and CPX_PARAM_ALL_MAX

Not all features map directly between Gurobi and CPLEX; this is one example. Here, CPLEX parameters are indexed by a number, while Gurobi parameters are indexed by a string (char* in C). If you want to get the full list of Gurobi parameters programmatically, look at the Parameters section in the header file include/gurobi_c.h.

Related

Hard Fault when dynamic memory allocaion in stm32f7

I am trying to implement a system so that it retrieves sound and extracts the mfcc of it. I'd like to implement my own mfcc function because librosa library wasn't implemented in C and other implementations of mfcc extractions doesn't yield the same outputs as librosa library does.
So I wrote a code, however, when I would like create hanning window, program doesn't take a step further and always stays the same statement while debugging. The statement is below:
float *mul = malloc(sizeof(float)*fftsize);
The whole code is as follows:
float* hanning(int fftsize){
float *mul = malloc(sizeof(float)*fftsize);
for (int i = 0; i<fftsize; i++){
mul[i] = 0.5 * (1 - cos(2*PI*i/(fftsize-1)));
}
return mul;
}
I put an LCD code to all error handler functions in stm32f7xx_it.c file to determine which fault I'm facing, and I see that it is hard_fault.
So what's the problem? I hope the issue is explained clearly. Due to the privacy, I couldn't put here whole code. Sorry for that. Thx in advance for your response.
Edit: I am chaning malloc to normal array with a variable length array. But still it takes me to HardFault_Handler function. SCB->SHCSR returns sometimes 65535 and sometimes 1.

Error: No operator "=" matches these operands in "Servo_Project.cpp", Line: 15, Col: 22

So I tried using code from another post around here to see if I could use it, it was a code meant to utilize a potentiometer to move a servo motor, but when I attempted to compile it is gave the error above saying No operator "=" matches these operands in "Servo_Project.cpp". How do I go about fixing this error?
Just in case ill say this, the boards I was trying to compile the code were a NUCLEO-L476RG, the board from the post I mentioned utilized Nucleo L496ZG board and a Tower Pro Micro Servo 9G.
#include "mbed.h"
#include "Servo.h"
Servo myservo(D6);
AnalogOut MyPot(A0);
int main() {
float PotReading;
PotReading = MyPot.read();
while(1) {
for(int i=0; i<100; i++) {
myservo = (i/100);
wait(0.01);
}
}
}
This line:
myservo = (i/100);
Is wrong in a couple of ways. First, i/100 will always be zero - integer division truncates in C++. Second, there's not an = operator that allows an integer value to be assigned to a Servo object. YOu need to invoke some kind of Servo method instead, likely write().
myservo.write(SOMETHING);
The SOMETHING should be the position or speed of the servo you're trying to get working. See the Servo class reference for an explanation. Your code tries to use fractions from 0-1 and thatvisn't going to work - the Servo wants a position/speed between 0 and 180.
You should look in the Servo.h header to see what member functions and operators are implemented.
Assuming what you are using is this, it does have:
Servo& operator= (float percent);
Although note that the parameter is float and you are passing an int (the parameter is also in the range 0.0 to 1.0 - so not "percent" as its name suggests - so be wary, both the documentation and the naming are poor). You should have:
myservo = i/100.0f;
However, even though i / 100 would produce zero for all i in the loop, that does not explain the error, since an implicit cast should be possible - even if clearly undesirable. You should look in the actual header you are using to see if the operator= is declared - possibly you have the wrong file or a different version or just an entirely different implementation that happens to use teh same name.
I also notice that if you look in the header, there is no documentation mark-up for this function and the Servo& operator= (Servo& rhs); member is not documented at all - hence the confusing automatically generated "Shorthand for the write and read functions." on the Servo doc page when the function shown is only one of those things. It is possible it has been removed from your version.
Given that the documentation is incomplete and that the operator= looks like an after thought, the simplest solution is to use the read() / write() members directly in any case. Or implement your own Servo class - it appears to be only a thin wrapper/facade of the PwmOut class in any case. Since that is actually part of mbed rather than user contributed code of unknown quality, you may be on firmer ground.

How do you read the values of individual features from a FeatureField in Lucene?

I'm using Lucene 7.6.0 and I've indexed a series of documents with a FeatureField named "features", that stores query-independent evidence (e.g., "indegree", "pagerank"). If I'm not mistaken, the theory is that these are stored as a term vector, where "indegree" and "pagerank" are stored as terms and their values are stored as the corresponding term frequencies.
I've tested some queries where I combined BM25 and each individual feature, and some return a different ranking, when compared to BM25 alone, but some others seem to have no effect. This might just be a coincidence, which is fine, but I would like to check whether the values were correctly indexed. How do I do this?
I've tried using Luke to inspect the index, but there is no term vector associated with the "features" field. The active flags for "features" are only "Idf", but I honestly can't find a way to access the frequencies for each document. The best I was able to do, in order to check whether the field had any value, was something like:
IndexReader reader = DirectoryReader.open(
FSDirectory.open(Paths.get("/tmp/lucene-index")));
reader.totalTermFreq(new Term("features", "indegree"));
This printed the number 33344, which does not match the value I indexed (a single document with indegree 10), however I suspect this might be codified somehow.
I know this API is still experimental, but I was wondering if anyone knew if it would be possible to retrieve the feature values, either for each document or globally somehow (maybe an anonymous vector, without a link to the corresponding documents).
I was able to verify the that the ranking by each feature matches the order for the data that I have. I also believe I was able to fairly reverse the provided relevance score to obtain the original feature value (I say "fairly", because I found what seem to be slightly rounding errors; let me know if it's an error instead). The code I used was the following:
IndexReader reader = DirectoryReader.open(
FSDirectory.open(Paths.get("/tmp/lucene-index")));
IndexSearcher searcher = new IndexSearcher(reader);
searcher.setSimilarity(new BM25Similarity(1.2f, 0.75f));
float w = 1.8f;
float k = 1f;
float a = 0.6f;
Query query = FeatureField.newSigmoidQuery("features", "indegree", w, k, a);
TopDocs hits = searcher.search(query, 5);
for (int i = 0; i < hits.scoreDocs.length; i++) {
Document doc = searcher.doc(hits.scoreDocs[i].doc);
float featureValue = (float) Math.pow(
(hits.scoreDocs[i].score / w * Math.pow(k, a))
/ (1 - hits.scoreDocs[i].score / w),
1 / a
);
System.out.println(featureValue + "\t" + doc.get("doc_id"));
}
reader.close();
The equation for featureValue is simply the sigmoid scaling of the static feature S (the "indegree" in this case) solved for S, based on the relevance score. You can find the original equation in the paper cited in Lucene's JavaDoc for FeatureField: https://dl.acm.org/citation.cfm?doid=1076034.1076106
Please let me know if you find any error with this solution, or if there is an easier way to inspect the index.

Pyomo - implicit conversion of pyomo numeric value to integer

I am trying to optimize a pyomo abstract model (m). The model has a (integer) parameter called a. I want to calculate another integer value while constructing a model. Let the other variable be c = a*(a-1)/2. And I want an array of binary variables of size c
For this I am writing the following lines -
#File - test.py#
from pyomo.environ import *
m = AbstractModel()
m.a = Param()
c = m.a*(m.a-1)/2
m.var = Var(range(1,c), within=Binary)
m.obj = Objective(expr = 0)
#File - data.dat#
param a := 5 ;
To solve this I ran - pyomo solve test.py data.dat --solver=glpk
After running this I get the following error:
Implicit conversion of Pyomo NumericValue type `<class
'pyomo.core.kernel.expr_coopr3._ProductExpression'>' to an integer
is disabled. This error is often the result of using Pyomo components as
arguments to one of the Python built-in math
module functions when defining expressions. Avoid this error by using Pyomo-
provided math functions.
I think the error comes when I try to take range(1,c). Correct me if I am wrong.
I have Python 2.7.12, Pyomo-5.3 (CPython-2.7.12 on Linux). I will have to ask the installation method to someone as I got it installed, so it might take time. I will update the installation method once I ask the person who installed it.
Thanks.
There are two things going on here:
You are evaluating a Param before it is defined.
You are implicitly casting a Pyomo expression to an integer.
The root of the problem is that you are treating an Abstract Model as if it was a Concrete Model. For Abstract models, when you declare m.a, you are only declaring the existence of a Parameter a. Python then continues to parse and execute the rest of your model. When it hits c = m.a*(m.a-1)/2, Python generates a Pyomo expression tree representing the right-hand-side. Finally, when it gets to m.var = Var(range(1,c), within=Binary), Python first executes the range(1,c) before calling the Var() constructor. range (a Python function) casts its arguments to int before generating the range list. That cast is what is generating the error.
You could get around that error by explicitly evaluating the value of the expression (c) with the (Pyomo) value(c) function. However, that will generate a different (perhaps more informative) error that you are evaluating a Param a before it has been constructed. This is because at this point the model is still abstract, and the data file that provides a value for a has not even been read.
The solution is to make an explicit Pyomo Set that will act as a placeholder for the expression and will not be constructed until the rest of the model is constructed (that is, the evaluation of the expression c is deferred until the value for a is available). For example:
from pyomo.environ import *
m = AbstractModel()
m.a = Param()
c = m.a*(m.a-1)/2
# Note that RangeSet includes the upper bound, whereas range stops one short
m.IDX = RangeSet(1,c-1)
m.var = Var(m.IDX, within=Binary)
m.obj = Objective(expr = 0)

Displaying top five solutions SCIP

I have written an integer programming model and solved it using SCIP. I can easily obtain the optimal solution but I am interested in also getting the next four best solutions as well. I can type in display allsolutions to show me some solutions in the SCIP shell but I'm interested at at most 4 other solutions and would like to do this from a c++ program rather than from the shell. How can I do this?
You can use the solution methods provided by scip.h to do so:
#define SOLSTOPRINT 5;
SCIP* scip;
SCIP_SOL** sols;
int nsols, i;
// ...
// put here your code to create a SCIP instance, read in a problem and call the
// the solving method of SCIP
// ...
sols = SCIPgetSols(scip);
nsols = SCIPgetNSols(scip);
for( i = 0; i < MIN(nsols, SOLSTOPRINT); ++i )
{
SCIP_CALL( SCIPprintSol(scip, sols[i], NULL, FALSE) );
}
SCIP stores the solutions automatically from best to worst, so that it suffices to iterate over the first 5 solutions of the sols-array. Please note that SCIP by default stores at most the
best 100 solutions found. You can change this behavior through the parameter limits/maxsol, e.g., by adding the line
SCIP_CALL( SCIPsetIntParam(scip, "limits/maxsol", 200) );
to the above code before solving the problem.