void ReadRWMolsFromSDF(const std::string &file, std::vector<RDKit::RWMol *> &mols) { try { RDKit::SDMolSupplier supplier(file); mols.reserve(supplier.length()); for (size_t i = 0; i < supplier.length(); ++i) { RDKit::ROMol *mol = supplier.next(); if (mol) { RDKit::RWMol *rwMol = new RDKit::RWMol(*mol); if (rwMol) { mols.push_back(rwMol); } delete mol; } } } catch (RDKit::BadFileException &exc) { SynchCout(std::string("Cannot read from file: ").append(file)); } }
int main(int argc, const char* argv[]){ IloEnv env; try{ IloModel model(env); IloInt i, j; const char* filename = "../../../examples/data/facility.data"; if (argc > 1) filename = argv[1]; std::ifstream file(filename); if (!file){ env.out() << "usage: " << argv[0] << " <file>" << std::endl; throw FileError(); } IloIntArray capacity(env), fixedCost(env); IloArray<IloIntArray> cost(env); IloInt nbLocations; IloInt nbStores; file >> nbLocations; file >> nbStores; capacity = IloIntArray(env, nbLocations); for(i = 0; i < nbLocations; i++){ file >> capacity[i]; } fixedCost = IloIntArray(env, nbLocations); for(i = 0; i < nbLocations; i++){ file >> fixedCost[i]; } for(j = 0; j < nbStores; j++){ cost.add(IloIntArray(env, nbLocations)); for(i = 0; i < nbLocations; i++){ file >> cost[j][i]; } } IloBool consistentData = (fixedCost.getSize() == nbLocations); consistentData = consistentData && nbStores <= IloSum(capacity); for (i = 0; consistentData && (i < nbStores); i++) consistentData = (cost[i].getSize() == nbLocations); if (!consistentData){ env.out() << "ERROR: data file '" << filename << "' contains inconsistent data" << std::endl; } IloIntVarArray supplier(env, nbStores, 0, nbLocations - 1); for (j = 0; j < nbLocations; j++) model.add(IloCount(supplier, j) <= capacity[j]); model.add(supplier[2] != supplier[7]); IloIntVarArray open(env, nbLocations, 0, 1); for (i = 0; i < nbStores; i++) model.add(open[supplier[i]] == 1); IloIntExpr obj = IloScalProd(open, fixedCost); for (i = 0; i < nbStores; i++) obj += cost[i][supplier[i]]; model.add(IloMinimize(env, obj)); IloCP cp(model); cp.setParameter(IloCP::LogVerbosity, IloCP::Quiet); cp.solve(); cp.out() << std::endl << "Optimal value: " << cp.getValue(obj) << std::endl; for (j = 0; j < nbLocations; j++){ if (cp.getValue(open[j]) == 1){ cp.out() << "Facility " << j << " is open, it serves stores "; for (i = 0; i < nbStores; i++){ if (cp.getValue(supplier[i]) == j) cp.out() << i << " "; } cp.out() << std::endl; } } } catch(IloException& e){ env.out() << " ERROR: " << e.getMessage() << std::endl; } env.end(); return 0; }