// Constructor, intended for root node Node::Node(ConstraintPtr constraints) : constraints(constraints->clone(true)), // Deep copy nodeId(getNextNodeId()) { objLowerBound = -INF; objUpperBound = INF; solLowerBound = std::vector<double>(constraints->getNumVariables(), 0.0); solUpperBound = std::vector<double>(constraints->getNumVariables(), 0.0); depth = 0; parentBranchingVariable = -1; // -1 for root node auto bvars = findBranchingVariables(this->constraints); // Initialize branching/pseudo costs double cost = 1.0; for (auto var : bvars) { if (var->getType() == VariableType::CONTINUOUS) { // Continuous pCostsContinuous.emplace(getVariableIndex(var), cost); } else { // Integer pCostsInteger.emplace(getVariableIndex(var), 1.0); } } assert(bvars.size() == pCostsInteger.size() + pCostsContinuous.size()); }
// Copy constructor - constraints are cloned Node::Node(const Node ©) : constraints(copy.constraints->clone(true)), // Deep copy nodeId(getNextNodeId()), depth(copy.depth), parentBranchingVariable(copy.parentBranchingVariable), objLowerBound(copy.objLowerBound), objUpperBound(copy.objUpperBound), solLowerBound(copy.solLowerBound), solUpperBound(copy.solUpperBound), pCostsInteger(copy.pCostsInteger), pCostsContinuous(copy.pCostsContinuous) { // Nothing to do here, all values set }
/* * Add a new node */ int Settings::addNode(Node type) { TelldusCore::MutexLocker locker(&mutex); int intNodeId = getNextNodeId(type); FILE *fp = fopen(CONFIG_FILE, "we"); // e for setting O_CLOEXEC on the file handle if (!fp) { return TELLSTICK_ERROR_PERMISSION_DENIED; } cfg_print(d->cfg, fp); // Print the config-file if (type == Device) { fprintf(fp, "device {\n id=%d\n}\n", intNodeId); // Print the new device } else if (type == Controller) { fprintf(fp, "controller {\n id=%d\n}\n", intNodeId); // Print the new controller } fclose(fp); // Re-read config-file cfg_free(d->cfg); readConfig(&d->cfg); return intNodeId; }