Skip to content

Commit be10903

Browse files
author
Andrea Hornakova
committed
removed alternative contructor for parameters - not working
1 parent cdfa0f9 commit be10903

File tree

9 files changed

+70
-18
lines changed

9 files changed

+70
-18
lines changed

solverILP/LifT_py/solveFromFiles.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515

1616
import disjointPathsPy as ldpPy
1717

18+
#Create a parser for parameters
1819
paramsParser=ldpPy.ParametersParser()
1920

21+
#Initializes parameters from file
2022
paramsParser.init_from_file("../data/exampleSolverILP/params_sequence_py.ini")
2123

22-
#Initializes structure for holding solver parameters. It expects the path to the solver parameter file.
24+
#Initializes structure for holding solver parameters. It expects either a ParameterParser or a string to string dictionary as an input
2325
params=ldpPy.DisjointParams(paramsParser)
2426

2527
#Constructor of structure for holding the mapping between time frames and graph vertices

solverILP/LifT_py/solveFromMatrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
paramsMap["OUTPUT_PATH"]="../data/exampleSolverILP/"
4747

4848

49-
#Initializes structure for holding solver parameters. It expects the path to the solver parameter file.
49+
#Initializes structure for holding solver parameters. It expects either a ParameterParser or a string to string dictionary as an input
5050
params=ldpPy.DisjointParams(paramsMap)
5151

5252
#Constructor of structure for holding the mapping between time frames and graph vertices

solverILP/include/disjoint-paths/disjointParams.hxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public:
5555

5656

5757
// DisjointParams(const std::string& fileName);
58-
DisjointParams(ParametersParser& paramsConstructor);
58+
// DisjointParams(ParametersParser& paramsConstructor);
5959
DisjointParams(std::map<std::string,std::string>& parsedParams);
6060
//DisjointParamsDisjointParamsDisjointParams(const std::stringstream& stream);
6161

@@ -247,7 +247,7 @@ public:
247247

248248
private:
249249
DisjointParams<T>(const DisjointParams<T>&);
250-
void initParameters(std::map<std::string,std::string>& parameters);
250+
// void initParameters(std::map<std::string,std::string>& parameters);
251251
DisjointParams();
252252

253253
std::ofstream& infoFile(){
@@ -343,10 +343,10 @@ private:
343343

344344
//}
345345

346-
template<class T>
347-
inline DisjointParams<T>::DisjointParams(ParametersParser& paramsConstructor){
348-
DisjointParams(paramsConstructor.getParsedStrings());
349-
}
346+
//template<class T>
347+
//inline DisjointParams<T>::DisjointParams(ParametersParser& paramsConstructor){
348+
// DisjointParams(paramsConstructor.getParsedStrings());
349+
//}
350350

351351
template<class T>
352352
inline DisjointParams<T>::DisjointParams(std::map<std::string,std::string>& parameters){

solverILP/include/disjoint-paths/disjointPathsData.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ inline void Data<T>::readCompleteGraph(){
555555
data.open(parameters.getGraphFileName());
556556
if(!data){
557557

558-
throw std::system_error(errno, std::system_category(), "failed to open "+parameters.getGraphFileName());
558+
throw std::system_error(errno, std::system_category(), "failed to open graph file "+parameters.getGraphFileName());
559559

560560
}
561561
char delim=',';

solverILP/include/disjoint-paths/disjointPathsMethods.hxx

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ std::vector<std::vector<T>> readLines(std::string inputFileName, char delim) {
7171

7272
inputFile.open(inputFileName);
7373
if (!inputFile){
74-
throw std::system_error(errno, std::system_category(), "failed to open "+inputFileName);
74+
throw std::system_error(errno, std::system_category(), "failed to open file with interval solution "+inputFileName);
7575
}
7676

7777
std::string line;
@@ -167,6 +167,7 @@ public:
167167
template<class PAR> VertexGroups(PAR& parameters){
168168
//std::vector<std::vector<size_t>> groups;
169169

170+
std::cout<<"time file name check 2 "<<parameters.getTimeFileName()<<std::endl;
170171
initFromFile(parameters.getTimeFileName(),parameters);
171172
// std::string line;
172173
// std::vector<std::string> strings;
@@ -309,11 +310,12 @@ inline void VertexGroups<T>::initFromFile(const std::string& fileName, const PAR
309310
size_t maxTimeToRead=parameters.getMaxTimeFrame();
310311

311312

313+
std::cout<<"time file name check 3 "<<fileName<<std::endl;
312314
std::ifstream timeData;
313315
try{
314316
timeData.open(fileName);
315317
if(!timeData){
316-
throw std::system_error(errno, std::system_category(), "failed to open "+fileName);
318+
throw std::system_error(errno, std::system_category(), "failed to open file with vertices in time layers "+fileName);
317319
}
318320

319321
unsigned int previousTime=1;
@@ -689,6 +691,7 @@ public:
689691
template<class PAR>
690692
CompleteStructure(PAR & configParameters)
691693
{
694+
std::cout<<"time file name check 1 "<<configParameters.getTimeFileName()<<std::endl;
692695
pVertexGroups=new VertexGroups<>(configParameters);
693696
VertexGroups<>& vg=*pVertexGroups;
694697
maxTime=vg.getMaxTime();
@@ -725,6 +728,8 @@ public:
725728
template<class PAR>
726729
void addEdgesFromFile(const std::string& fileName,PAR& params);
727730
void addEdgesFromMatrix(size_t time1,size_t time2,const py::array_t<double> inputMatrix);
731+
template<class PAR>
732+
void addEdgesFromVectors(const py::array_t<size_t>edges,const py::array_t<double> costs,PAR& params);
728733
const VertexGroups<>& getVertexGroups(){
729734
return *pVertexGroups;
730735
}
@@ -742,6 +747,49 @@ private:
742747

743748
};
744749

750+
template<class T>
751+
template<class PAR>
752+
inline void CompleteStructure<T>::addEdgesFromVectors(const py::array_t<size_t> edges,const py::array_t<double> costs,PAR& params){
753+
char delim=',';
754+
VertexGroups<>& vg=*pVertexGroups;
755+
756+
const auto edgeVector=edges.unchecked<2>();
757+
const std::size_t dim1=edgeVector.shape(0);
758+
const std::size_t dim2=edgeVector.shape(1);
759+
const auto costVector=costs.unchecked<1>();
760+
const size_t dimOfCosts=costVector.shape(0);
761+
762+
763+
if(dim2!=2){
764+
std::string message="Wrong dimension of edge array, second dimension 2 expected";
765+
throw std::invalid_argument(message);
766+
}
767+
if(dim1!=dimOfCosts){
768+
std::string message="Dimension of edge array and edge costs do not match.";
769+
throw std::invalid_argument(message);
770+
}
771+
772+
params.getControlOutput()<<"Reading base edges from vector. "<<std::endl;
773+
params.writeControlOutput();
774+
for (size_t i=0;i<dim1;i++) {
775+
size_t v=edgeVector(i,0);
776+
size_t w=edgeVector(i,1);
777+
double edgeCost=costVector(i);
778+
779+
size_t l0=vg.getGroupIndex(v);
780+
size_t l1=vg.getGroupIndex(w);
781+
//std::cout<<std::to_string(l0)<<", "<<std::to_string(l1)<<std::endl;
782+
if(v>vg.getMaxVertex()||w>vg.getMaxVertex()) continue;
783+
//std::cout<<"edge "<<v<<" "<<w<<std::endl;
784+
785+
if(l1-l0<=params.getMaxTimeGapComplete()){
786+
completeGraph.insertEdge(v,w);
787+
completeScore.push_back(edgeCost);
788+
}
789+
}
790+
}
791+
792+
745793
template<class T>
746794
inline void CompleteStructure<T>::addEdgesFromMatrix(size_t time1,size_t time2,const py::array_t<double> inputMatrix){
747795

@@ -823,7 +871,7 @@ inline void CompleteStructure<T>::addEdgesFromFile(const std::string& fileName,P
823871
try{
824872
data.open(fileName);
825873
if(!data){
826-
throw std::system_error(errno, std::system_category(), "failed to open "+fileName);
874+
throw std::system_error(errno, std::system_category(), "failed to open graph file "+fileName);
827875
}
828876

829877
std::getline(data, line);

solverILP/include/disjoint-paths/disjointStructure.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ parameters(configParameters)
207207
try{
208208
graphFile.open(parameters.getGraphFileName());
209209
if(!graphFile){
210-
throw std::system_error(errno, std::system_category(), "failed to open "+parameters.getGraphFileName());
210+
throw std::system_error(errno, std::system_category(), "failed to open graph file "+parameters.getGraphFileName());
211211
}
212212
readGraph(graphFile,maxVertex,delim);
213213
if(!parameters.isAutomaticLifted()){

solverILP/include/disjoint-paths/parametersconstructor.hxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ParametersParser{
2121
try{
2222
data.open(fileName);
2323
if (!data){
24-
throw std::system_error(errno, std::system_category(), "failed to open "+fileName);
24+
throw std::system_error(errno, std::system_category(), "failed to open parameter file "+fileName);
2525
}
2626
bool solverPart=false;
2727
std::string line;
@@ -38,6 +38,7 @@ class ParametersParser{
3838
throw std::runtime_error("Config file does not contain \"[SOLVER]\". ");
3939
}
4040
initFromStream(data);
41+
data.close();
4142

4243
}
4344

solverILP/src/disjoint-paths/disjointPathsPython.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ PYBIND11_MODULE(disjointPathsPy, m) {
1919

2020
py::class_<disjointPaths::ParametersParser>(m,"ParametersParser")
2121
.def(py::init<>())
22-
.def("init_from_file",&disjointPaths::ParametersParser::initFromFile,"Parses parameters from a file")
23-
.def("init_from_stream",&disjointPaths::ParametersParser::initFromStream<std::stringstream>,"Parses parameters from a stream");
22+
.def("init_from_file",&disjointPaths::ParametersParser::initFromFile,"Parses parameters from a file");
23+
// .def("init_from_stream",&disjointPaths::ParametersParser::initFromStream<std::stringstream>,"Parses parameters from a stream");
2424

2525

2626
py::class_<disjointPaths::DisjointParams<>>(m, "DisjointParams")
27-
.def(py::init<disjointPaths::ParametersParser&>())
2827
.def(py::init<std::map<std::string,std::string>&>());
2928

3029
py::class_<disjointPaths::VertexGroups<>>(m, "TimeFramesToVertices")
@@ -35,6 +34,7 @@ PYBIND11_MODULE(disjointPathsPy, m) {
3534
py::class_<disjointPaths::CompleteStructure<>>(m, "GraphStructure")
3635
.def(py::init<disjointPaths::VertexGroups<> &>())
3736
.def("add_edges_from_array", &disjointPaths::CompleteStructure<>::addEdgesFromMatrix, "Initializes edges of the graph between two time frames from a matrix.")
37+
.def("add_edges_from_vectors", &disjointPaths::CompleteStructure<>::addEdgesFromVectors<disjointPaths::DisjointParams<>>, "Initializes edges of the graph from an Nx2 array of size_t with edge vertices and an Nx1 array of doubles with costs.")
3838
.def("add_edges_from_file", &disjointPaths::CompleteStructure<>::addEdgesFromFile<disjointPaths::DisjointParams<>>, "Initializes all edges of the graph from a file.");
3939

4040
// m.def("solve_ilp", py::overload_cast<disjointPaths::DisjointParams<>&, disjointPaths::CompleteStructure<>&>(&disjointPaths::solver_ilp_intervals<>), "Solve lifted disjoint paths");

solverILP/src/disjoint-paths/runDisjointPaths.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,15 @@ try
107107
disjointPaths::ParametersParser parametersParser;
108108
parametersParser.initFromFile(parameters.configFile);
109109

110-
disjointPaths::DisjointParams<size_t> disjointParameters(parametersParser);
110+
disjointPaths::DisjointParams<size_t> disjointParameters(parametersParser.getParsedStrings());
111111
if(disjointParameters.isParametersSet()){
112112
if(disjointParameters.getMaxTimeLifted()==0){
113113
std::vector<std::vector<size_t>> paths=disjointPaths::solver_flow_only(disjointParameters);
114114
disjointPaths::writeOutputToFile(paths,disjointParameters.getOutputFileName() + "-all-paths-FINAL.txt");
115115

116116
}
117117
else{
118+
std::cout<<"time file name check 0 "<<disjointParameters.getTimeFileName()<<std::endl;
118119

119120
disjointPaths::CompleteStructure<> cs(disjointParameters);
120121
std::vector<std::vector<size_t>> paths=disjointPaths::solver_ilp<size_t>(disjointParameters,cs);

0 commit comments

Comments
 (0)