static int64_t path_parent_child(const char *path, const char **child, int flags) { int64_t parent_inum; uint max_len, leaf_idx; mode_t leaf_type; max_len = PAGE_SIZE; leaf_idx = path_get_leaf(path, &leaf_type); if ((flags & NO_DIR) && S_ISDIR(leaf_type)) return -EISDIR; if (path[0] == '/') assert(leaf_idx != 0); if (leaf_idx == 0) parent_inum = current->working_dir; else if (leaf_idx >= max_len) return -ENAMETOOLONG; else { char *parent = kmalloc(leaf_idx + 1); memcpy(parent, path, leaf_idx); parent[leaf_idx] = '\0'; parent_inum = name_i(parent); kfree(parent); if (parent_inum < 0) return parent_inum; } *child = &path[leaf_idx]; return parent_inum; }
/* * -ENOENT, -ENOTDIR, -ENAMETOOLONG */ int sys_stat(const char *path, struct stat *buf) { uint64_t inum; inum = name_i(path); if (inum < 0) return inum; fill_statbuf(inum, buf); return 0; }
/* * -ENOENT, -ENOTDIR, -ENAMETOOLONG */ int sys_chdir(const char *path) { int64_t inum; inum = name_i(path); if (inum < 0) return inum; if (!is_dir(inum)) return -ENOTDIR; assert(inum != 0); current->working_dir = inum; return 0; }
int sys_link(const char *oldpath, const char *newpath) { int64_t inum, parent_inum; const char *child; struct inode *inode; parent_inum = path_parent_child(newpath, &child, OK_DIR); if (parent_inum < 0) return parent_inum; inum = name_i(oldpath); if (inum < 0) return inum; inode = inode_get(inum); return ext2_new_dir_entry(parent_inum, inum, child, inode_mode_to_dir_entry_type(inode->mode)); }
/* * -EINVAL, -EEXIST, -ENOENT, -ENOTDIR, -ENAMETOOLONG, -EISDIR */ int sys_open(const char *path, int flags, __unused mode_t mode) { int64_t parent_inum, inum, fd; struct file *file; const char *child; if ((flags & O_ACCMODE) == 0) return -EINVAL; if ((flags & O_TRUNC) && (flags & O_APPEND || (flags & O_WRONLY) == 0)) return -EINVAL; inum = name_i(path); if (flags & O_CREAT) { if (inum > 0 && (flags & O_EXCL)) return -EEXIST; if (inum == -ENOENT) { parent_inum = path_parent_child(path, &child, NO_DIR); inum = (parent_inum < 0) ? parent_inum : file_new(parent_inum, child, EXT2_FT_REG_FILE); } } if (inum < 0) return inum; if (is_dir(inum)) return -EISDIR; file = kmalloc(sizeof(*file)); file_init(file, inum, flags); fd = unrolled_insert(¤t->fdtable, file); if (flags & O_TRUNC) file_truncate(inum); if (flags & O_APPEND) assert(sys_lseek(fd, 0, SEEK_END) > 0); return fd; }
void BppSolver::generateBranches(real lp_value, CoupleItem couple, BranchNode& currentNode, TreeNodes& nodes) { BranchNode separateBranch(lp_value, couple, SEPARATE, currentNode); BranchNode togetherBranch(lp_value, couple, TOGETHER, currentNode); std::vector<std::size_t> cols_i; std::vector<std::size_t> cols_j; std::vector<std::size_t> invalide_together(BPmodel.nbVars()); std::vector<std::size_t> invalide_separate(BPmodel.nbVars()); IloExpr::LinearIterator it_i = BPmodel.getLinearCoefIterator(couple.first); IloExpr::LinearIterator it_j = BPmodel.getLinearCoefIterator(couple.second); bool validColumn_it; while (it_i.ok()) { std::string name_i(it_i.getVar().getName()); int si = std::stoi(name_i.substr(1)); validColumn_it = true; for (auto cols : currentNode.incumbentInvalidColumns) { if (!(validColumn_it = (cols->find(si) == cols->end()))) break; } if (validColumn_it) cols_i.push_back(std::stoi(name_i.substr(1))); ++it_i; } while (it_j.ok()) { std::string name_j(it_j.getVar().getName()); int sj = std::stoi(name_j.substr(1)); validColumn_it = true; for (auto cols : currentNode.incumbentInvalidColumns) { if (!(validColumn_it = (cols->find(sj) == cols->end()))) break; } if (validColumn_it) cols_j.push_back(std::stoi(name_j.substr(1))); ++it_j; } std::vector<std::size_t>::iterator it; it = std::set_intersection(cols_i.begin(), cols_i.end(), cols_j.begin(), cols_j.end(), invalide_separate.begin()); invalide_separate.resize(it - invalide_separate.begin()); for (auto i : invalide_separate) separateBranch.invalidColumns->insert(i); it = std::set_symmetric_difference(cols_i.begin(), cols_i.end(), cols_j.begin(), cols_j.end(), invalide_together.begin()); invalide_together.resize(it - invalide_together.begin()); for (auto i : invalide_together) togetherBranch.invalidColumns->insert(i); srand(time(0)); int randomval = rand() % 2; if (randomval == 1) { TogetherBranch(togetherBranch, separateBranch, nodes); } else { SeparateBranch(togetherBranch, separateBranch, nodes); } }
CoupleItem BppSolver::ryanFosterCouple(BranchNode& node) { // get var values auto& Xs = BPmodel.getPrimalValues(); #ifdef DBG_OUTPUT for (int i = 0; i < BPVars.getSize(); i++) std::cout << Xs[i] << " "; std::cout << std::endl; #endif std::vector<std::size_t> vec_shuffled(Xs.getSize()); std::iota(vec_shuffled.begin(), vec_shuffled.end(), 0); // shuffle auto engine = std::default_random_engine(std::random_device{}()); std::shuffle(vec_shuffled.begin(), vec_shuffled.end(), engine); std::list<std::size_t> vi(vec_shuffled.begin(), vec_shuffled.end()); std::shuffle(vec_shuffled.begin(), vec_shuffled.end(), engine); std::list<std::size_t> vj(vec_shuffled.begin(), vec_shuffled.end()); for (auto it = vi.begin(); it != vi.end(); it++) { int i = *it; auto jt = vj.begin(); while (jt != vj.end()) { int j = *jt; if (i == j) jt = vj.erase(jt); else { IloExpr::LinearIterator it_i = BPmodel.getLinearCoefIterator(i); IloExpr::LinearIterator it_j = BPmodel.getLinearCoefIterator(j); real sumVars = 0.0; for (; ; ) { // get index of the variables via thier names std::string name_i(it_i.getVar().getName()); std::string name_j(it_j.getVar().getName()); // si and sj are the column index of the iterators int si = std::stoi(name_i.substr(1)); int sj = std::stoi(name_j.substr(1)); // booleans for validity of the columns bool validColumn_it = true; // i and j are in the same bin if (si == sj) { for (auto cols : node.incumbentInvalidColumns) { if (!(validColumn_it = (cols->find(sj) == cols->end()))) break; } if (validColumn_it) validColumn_it = (node.invalidColumns->find(si) == node.invalidColumns->end()); if (validColumn_it && (Xs[si] > 0.0)) sumVars += Xs[si]; } // some requirement to increment the iterator // since they itarate only over non zero coefs if (si <= sj) ++it_i; ++it_j; // stop condition if (!it_i.ok() || !it_j.ok()) break; } real _dumy; real frac = modf(sumVars, &_dumy); if (frac >= 0.0001) { return std::make_pair(i, j); } ++jt; } } } }