Getting the node depth of current node - c++

I have made a user cut callback that adds some cuts to the model I am working on. This works perfectly fine. I want to add these cuts, only to the top nodes of the search tree. The problem is, that I cannot figure out how to retrieve the depth of the current node. I have made a node callback that increments an integer variable every time it is called. This means that I can just do nothing in the cut callback when this integer exceeds some number. But then I do not now, if cplex has fx. only created nodes on left branches, meaning that no cuts are added to nodes on right branches or vise versa.
Looking in the documentation for node callbacks
http://pic.dhe.ibm.com/infocenter/cosinfoc/v12r4/index.jsp?opic=%2Filog.odms.cplex.help%2Frefpythoncplex%2Fhtml%2Fcplex.callbacks.NodeCallback-class.html
I see that there is a getDepth() method, that takes as argument a node identifier. But how to get this identifier, I simply cannot figure out.

CPLEX version 12.10.0.0 has the method
getCurrentNodeDepth()
You can call it inside your ILOUSERCUTCALLBACK method and it will give the current node depth as a long value.
You can check for more details here:
https://www.ibm.com/support/knowledgecenter/SSSA5P_12.10.0/ilog.odms.cplex.help/refdotnetcplex/html/M_ILOG_CPLEX_Cplex_MIPCallback_GetCurrentNodeDepth.htm

I was trying the same thing in C++.
I was trying to work with the function getDepth(), that takes as argument a node identifier.
But I couldn't figure out how to obtain the node identifier.
It is not clear from the documentation, but:
When the node callback is invoked, the next node to be processed is the node at index 0.
Then, to know the depth of the current node, you need to use index 0 as the identifier.

Using the callable library:
CPXgetcallbacknodeinfo(env, cbdata, wherefrom, 0, CPX_CALLBACK_INFO_NODE_DEPTH, &depth);
Sorry, I do not know much about the concert technology.

Related

How to add a Branch to An Already Existing TTree: ROOT

I have an existing TTree after doing a simulation. I would like to add a Branch to this TTree and I want to call it Muon.Mass to the tree. I would also want to give the Muon.Mass branch a value of 0.1.
How can I write that?
I have seen how to create TTrees from scratch and to have branches of different variables. But I am not sure exactly what to do when I already have a TTree.
You can call the TTree::Branch method on an existing TTree the same way as for a new TTree. Just for filling you need to ensure you only fill the branch. (this is a strongly cut down example from https://github.com/pseyfert/tmva-branch-adder)
void AddABranch(TTree* tree) {
Float_t my_local_variable;
TBranch* my_new_branch = tree->AddBranch( ... /* use address of my_local_variable */ );
for (Long64_t entry = 0 ; entry < tree->GetEntries() ; ++e ) {
tree->GetEntry();
/* something to compute my_local_variable */
my_new_branch->Fill();
}
}
As alternative you might want to look at the root tutorials for tree friends.
As a side note, depending what you want to do with the tree / whom you give the tree to, I advise against using . in branch names as they cause headache when running MakeClass (branch names can contain periods, but c++ variables can't, so the automatically generated class members for each branch will undergo character replacement).

SCIP: How to resolve LP after catching a 'node infeasibility' event,

I have a working column generation algorithm in SCIP. Due to specific constraints that I include while generating columns, it might happen that the last pricing round determines that the root node is infeasible (by the Farkas pricer of course).
In case that happens, I would like to 1) relax those specific constraints, 2) resolve the LP, and 3) start pricing columns again.
So, I have created my own EventHandler class, catching the node infeasibility event:
SCIP_DECL_EVENTINITSOL(EventHandler::scip_initsol)
{
SCIP_CALL( SCIPcatchEvent(scip_, SCIP_EVENTTYPE_NODEINFEASIBLE, eventhdlr, NULL, NULL));
return SCIP_OKAY;
}
And, corresponding, the scip_exec virtual method:
SCIP_DECL_EVENTEXEC(EventHandler::scip_exec)
{
double cur_rhs = SCIPgetRhsLinear(scip_, *d_varConsInfo).c_primal_obj_cut);
SCIPchgRhsLinear (scip_, (*d_varConsInfo).c_primal_obj_cut, cur_rhs + DELTA);
return SCIP_OKAY;
}
Where (*d_varConsInfo).c_primal_obj_cut is the specific constraint to be changed, DELTA is a global parameter, and cur_rhs is the current right hand side of the specific constraint. This function is neately called after the node infeasibility proof, however, I do not know how to 'tell' scip that the LP should be resolved and possible new columns should be included. Can somebody help me out with this?
When the event handler catches the NODEINFEASIBLE event, it is already too late to change something about the infeasibility of the problem, the node processing is already finished. Additionally, you are not allowed to change the rhs of a constraint during the solving process (because this means that reductions done before would potentially be invalid).
I would suggest the following: if your Farkas pricing is not able to identify new columns to render the LP feasible again, the node will be declared to be infeasible in the following. Therefore, at the end of Farkas pricing (if you are at the root node), you could just price an auxiliary variable that you add to the constraint that you want to relax, with bounds corresponding to your DELTA. Note that you need to have marked the constraint to be modifiable when creating it. Then, since a variable was added, SCIP will trigger another pricing round.
maybe you should take a look into the PRICERFARKAS method of SCIP (https://scip.zib.de/doc/html/PRICER.php#PRICER_FUNDAMENTALCALLBACKS).
If the current LP relaxation is infeasible, it is the task of the
pricer to generate additional variables that can potentially render
the LP feasible again. In standard branch-and-price, these are
variables with positive Farkas values, and the PRICERFARKAS method
should identify those variables.

Persistent and ephemeral nodes in ZooKeeper

I want to know how to create persistent nodes in ZooKeeper, using C++ client. I know from documentation, that there is a method zoo_acreate. And documentation says about this method that:
This method will create a node in ZooKeeper. A node can only be created if it does not already exists. The Create Flags affect the creation of nodes. If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the client session goes away. If the ZOO_SEQUENCE flag is set, a unique monotonically increasing sequence number is appended to the path name.
But, unfortunatelly, almost as always with C++ libraries, this library completely lacks reasonable teeny-weeny examples demonstarting the usage of the library methods. As for example in this case where documentation page is about zoo_acreate method, but some terribly looking example is totally about something else (it does not even mention zoo_acreate method).
So, my question is how to set these flags ZOO_EPHEMERAL and ZOO_SEQUENCE. It would be great to see this in the context of some tiny examples. Thanks!
Googling for "zoo_acreate ZOO_EPHEMERAL" gave this as the seventh result:
string path = "/nodes/";
string value = "data";
int rc = zoo_acreate(zh, path.c_str(), value.c_str(), value.length(),
&ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL | ZOO_SEQUENCE, &czoo_created, &where);
Source: https://issues.apache.org/jira/browse/ZOOKEEPER-348

Flex 4.5 List - ensureIndexIsVisible error

In my application I have a list of items which can be changed either by clicking on the list, using a next/previous button or via a menu which allows them to jump between items (mainly for the phone version which doesn't display the list).
I'm using the ensureIndexIsVisible function after the data provider for the list has been populated. However sometimes when I return to this page the application crashes out with the following error:
RangeError: Error #1125: The index 0 is out of range 0.
at spark.layouts.supportClasses::LinearLayoutVector/getMajorSize()[E:\dev\4.y\frameworks\projects\spark\src\spark\layouts\supportClasses\LinearLayoutVector.as:420]
The strange thing is that the index I pass into the function when it crashes isn't 0. It can be 1 or 3 or presumably anything. I can stop the application from crashing if I remove the function call but I need the list to show what question is currently selected.
The actual line that crashes is this:
var block:Block = blockTable[index >> BLOCK_SHIFT]; from a function called getMajorSize
As this has gone unanswered for so long I thought I'd answer it myself back with what I've recently ended up doing.
I managed to get this issue resolved by mainly changing the points where I called the function. i.e. it was being called too early.
However I recently changed over to using a custom function that someone else posted as I found that the ensureIndexIsVisible was often jumping to the wrong position in the list (due to a variety in heights of the items).
The function can be found on this question and is called scrollToIndex:
Scroll to selected item in Flex 4 Spark List component
This error is related to FLEX-28291, which should be fixed in the next version of Apache Flex (probably 4.14).

wxWidgets AddRoot() on wxTreeCtrl fails to add more then one node

I'm using wxWidgets 2.8.11 on Windows 7 64 Bit. I created a wxTreeCtrl control, which as the name suggests, is a tree control. You can add Root nodes by calling AddRoot(), however it seems to only work the first time of calling it.
Here is the code where I create the Tree:
newHandler-> sendPacketTree = new wxTreeCtrl(newHandler->sendGroupBox,4,wxPoint(7,12),wxSize(newHandler->sendGroupBox->GetSize().x-14,newHandler->sendGroupBox->GetSize().y-20),wxTR_DEFAULT_STYLE);
Here is what I'm doing just as a test:
this->sendPacketTree->AddRoot(wxT("Test1"));
this->sendPacketTree->AddRoot(wxT("Test2"));
However, only the first root node appears in the Tree, and the second node doesn't appear (or any other node after the first node for that matter)
Does anyone know why this is happening, or how I can get around this? I'm stumped.
I found a solution on my own. I thought that AddRoot() allowed you to add more then one root. It turns out you can only have one root, but you are able to hide the actual "root", and any children of the root will look like a root with the wxTR_HIDE_ROOT style set.