Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ set(CMAKE_USER_MAKE_RULES_OVERRIDE
set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX
${CMAKE_CURRENT_SOURCE_DIR}/cmake/cxx_flag_overrides.cmake)

project(MMST)
project(OPW)

#set(MMST_VERSION_MAJOR 0)
#set(MMST_VERSION_MINOR 1)
#set(PACKAGE_VERSION ${MMST_VERSION_MAJOR}.${MMST_VERSION_MINOR})
#set(OPW_VERSION_MAJOR 0)
#set(OPW_VERSION_MINOR 1)
#set(PACKAGE_VERSION ${OPW_VERSION_MAJOR}.${OPW_VERSION_MINOR})

#set(MMST_COMPILED ssd${MMST_VERSION_MAJOR}${MMST_VERSION_MINOR})
set(MMST_COMPILED mmst)
#set(OPW_COMPILED ssd${OPW_VERSION_MAJOR}${OPW_VERSION_MINOR})
set(OPW_COMPILED opw)

# Static so I can copy the executable to another version
# Check link for other possible options:
Expand Down
674 changes: 674 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# opw

`opw` is a wrapper library in C++ for commercial and open source solvers

## Setup

(1) Install at least one of the currently supported solvers: IBM CPLEX and GNU Linear Programming Kit (GLPK)

(2) Install Boost

## Building
```
$ opw/build$ cmake ..

$ opw/build$ make
```

## Running
```
Usage:
opw input [options]
```

To solve the Generalized Assigment Problem using GLPK with default options for the solver, simply run from inside the `build/` directory:

```
$ ./opw --input=../tests/GeneralizedAssignmentProblem/gap_test.txt --debug=2 --model=gap --solver=glpk
```
2 changes: 0 additions & 2 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
CPLEX Error 3003: Not a mixed-integer problem.


- Add LP printing option? used in Tesco no reversal
- Add user and lazy cuts before optimisation?
- To incumbent callback add Check(CPXsetintparam(env, CPX_PARAM_MIPCBREDLP, CPX_OFF), env);

79 changes: 79 additions & 0 deletions cmake/FindGLPK.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Find GLPK header and library.
#

# This module defines the following uncached variables:
# GLPK_FOUND, if false, do not try to use GLPK.
# GLPK_INCLUDE_DIRS, where to find glpk.h.
# GLPK_LIBRARIES, the libraries to link against to use the GLPK library
# GLPK_LIBRARY_DIRS, the directory where the GLPK library is found.

if(MSVC)
find_path(
GLPK_INCLUDE_DIR
glpk.h
PATHS "C:/glpk-4.65/src/"
)

if( GLPK_INCLUDE_DIR )
find_library(
GLPK_LIBRARY
glpk_4_65.lib glpk_4_65.dll
PATHS "C:/glpk-4.65/w64/"
)
if( GLPK_LIBRARY )
set(GLPK_LIBRARY_DIR "")
get_filename_component(GLPK_LIBRARY_DIRS ${GLPK_LIBRARY} PATH)
# Set uncached variables as per standard.
set(GLPK_FOUND ON)
set(GLPK_INCLUDE_DIRS ${GLPK_INCLUDE_DIR})
set(GLPK_LIBRARIES ${GLPK_LIBRARY})
endif(GLPK_LIBRARY)
else(GLPK_INCLUDE_DIR)
message(FATAL_ERROR "FindGLPK: Could not find glpk.h")
endif(GLPK_INCLUDE_DIR)

if(GLPK_FOUND)
if(NOT GLPK_FIND_QUIETLY)
message(STATUS "FindGLPK: Found both glpk.h and glpk_4_65.lib")
endif(NOT GLPK_FIND_QUIETLY)
else(GLPK_FOUND)
if(GLPK_FIND_REQUIRED)
message(FATAL_ERROR "FindGLPK: Could not find glpk.h and/or glpk_4_65.lib")
endif(GLPK_FIND_REQUIRED)
endif(GLPK_FOUND)

else(MSVC)
find_path(
GLPK_INCLUDE_DIR
glpk.h
PATHS /usr/local/include /usr/include
)

if( GLPK_INCLUDE_DIR )
find_library(
GLPK_LIBRARY
NAMES libglpk.so libglpk.a
PATHS /usr/lib64 /usr/local/lib /usr/lib
)
if( GLPK_LIBRARY )
set(GLPK_LIBRARY_DIR "")
get_filename_component(GLPK_LIBRARY_DIRS ${GLPK_LIBRARY} PATH)
# Set uncached variables as per standard.
set(GLPK_FOUND ON)
set(GLPK_INCLUDE_DIRS ${GLPK_INCLUDE_DIR})
set(GLPK_LIBRARIES ${GLPK_LIBRARY})
endif(GLPK_LIBRARY)
else(GLPK_INCLUDE_DIR)
message(FATAL_ERROR "FindGLPK: Could not find glpk.h")
endif(GLPK_INCLUDE_DIR)

if(GLPK_FOUND)
if(NOT GLPK_FIND_QUIETLY)
message(STATUS "FindGLPK: Found both glpk.h and libglpk.a")
endif(NOT GLPK_FIND_QUIETLY)
else(GLPK_FOUND)
if(GLPK_FIND_REQUIRED)
message(FATAL_ERROR "FindGLPK: Could not find glpk.h and/or libglpk.a")
endif(GLPK_FIND_REQUIRED)
endif(GLPK_FOUND)
endif()
39 changes: 19 additions & 20 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
include_directories(${MMST_SOURCE_DIR}/src)
link_directories(${MMST_BINARY_DIR}/src)

include_directories(${OPW_SOURCE_DIR}/src)
link_directories(${OPW_BINARY_DIR}/src)

SET (Boost_USE_STATIC_LIBS ON)
SET (Boost_USE_STATIC_RUNTIME ON)
find_package(Boost COMPONENTS)
#find_package(Boost COMPONENTS regex REQUIRED)

#find_library(SQLITE_LIBRARY_RELEASE sqlite3 VARIANT static)

find_package(CPLEX)
if (CPLEX_FOUND)
else ()
endif ()
find_package(GLPK)



add_executable(${MMST_COMPILED}
add_executable(${OPW_COMPILED}
main.cc
Util.h Util.cc
Option.h Option.cc
Expand All @@ -25,20 +19,25 @@ add_executable(${MMST_COMPILED}
Execute.h Execute.cc
Model.h Model.cc
Solver.h Solver.cc

# solvers
CPLEX.h CPLEX.cc
GLPK.h GLPK.cc

Solution.h Solution.cc

# models
DataCapitalBudgeting.h DataCapitalBudgeting.cc
ModelCapitalBudgeting.h ModelCapitalBudgeting.cc
DataGAP.h DataGAP.cc
ModelGAP.h ModelGAP.cc
)

target_link_libraries(${MMST_COMPILED} m)
#target_link_libraries(${MMST_COMPILED} ${SQLITE_LIBRARY_RELEASE})
#target_link_libraries(${MMST_COMPILED} sqlite3)
target_link_libraries(${MMST_COMPILED} pthread)
#target_link_libraries(${MMST_COMPILED} boost_regex)
target_link_libraries(${MMST_COMPILED} ${Boost_LIBRARIES})
target_link_libraries(${MMST_COMPILED} cplex-library)
target_link_libraries(${MMST_COMPILED} cplex-concert)
target_link_libraries(${MMST_COMPILED} ilocplex)
target_link_libraries(${MMST_COMPILED} dl)
target_link_libraries(${OPW_COMPILED} m)
target_link_libraries(${OPW_COMPILED} pthread)
target_link_libraries(${OPW_COMPILED} ${Boost_LIBRARIES})
target_link_libraries(${OPW_COMPILED} cplex-library)
target_link_libraries(${OPW_COMPILED} cplex-concert)
target_link_libraries(${OPW_COMPILED} glpk)
target_link_libraries(${OPW_COMPILED} ilocplex)
target_link_libraries(${OPW_COMPILED} dl)
20 changes: 15 additions & 5 deletions src/CPLEX.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
/**
* CPLEX.cc
/*
* Copyright 2018
* Cristiano Arbex Valle
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* opw is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Copyright(c) 2018
* Cristiano Arbex Valle
* All rights reserved.
*/

#include "CPLEX.h"
Expand Down
20 changes: 15 additions & 5 deletions src/CPLEX.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
/**
* CPLEX.h
/*
* Copyright 2018
* Cristiano Arbex Valle
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* opw is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Copyright(c) 2018
* Cristiano Arbex Valle
* All rights reserved.
*/

#ifndef CPLEX_H
Expand Down
2 changes: 1 addition & 1 deletion src/Data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


Data::Data() {
debug = Options::getInstance()->getIntOption("debug");
debug = Options::getInstance()->getIntOption("debug");
}

Data::~Data() {
Expand Down
105 changes: 105 additions & 0 deletions src/DataGAP.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright 2020 Arthur Moreira
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* opw is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

#include "DataGAP.h"
#include "Options.h"
#include <iostream>
#include <fstream>
#include <string>

DataGAP::DataGAP() : Data() {
numVariables = 0;
numTasks = 0;
}

DataGAP::~DataGAP() {
}


void DataGAP::readData() {

if (debug) printf("Initialising data for the Generalised Assignment Problem\n\n");

std::ifstream inputFile;

// string file_path = Options::getInstance()->getInputFile();
string file_path = Options::getInstance()->getStringOption("input");

inputFile.open(file_path);
if (inputFile.is_open()) {

inputFile >> numVariables;
inputFile >> numTasks;

agentBudget.resize(numVariables);
profitMatrix.resize(numTasks);
weightMatrix.resize(numTasks);
for (int i = 0; i < numTasks; i++) {
profitMatrix[i].resize(numVariables);
weightMatrix[i].resize(numVariables);
}

for (int j = 0; j < numVariables; j++) {
for (int i = 0; i < numTasks; i++) {
inputFile >> profitMatrix[i][j];
}
}
for (int j = 0; j < numVariables; j++) {
for (int i = 0; i < numTasks; i++) {
inputFile >> weightMatrix[i][j];
}
}
for (int j = 0; j < numVariables; j++) {
inputFile >> agentBudget[j];
}
}
else std::cout << "Unable to open file\n";

inputFile.close();

}

void DataGAP::print() {
if (debug) {
printf("Num agents: %2d\n", numVariables);
printf("Num tasks: %2d\n", numTasks);
}
}


double DataGAP::getAgentBudget(int i) const {
if (i >= numVariables) Util::throwInvalidArgument("Error: Out of range parameter i in getAgentBudget");
return agentBudget[i];
}

double DataGAP::getProfitMatrix(int i, int j) const {
if (i >= numTasks) {Util::throwInvalidArgument("Error: Out of range parameter i in getProfitMatrix");}
else if (j >= numVariables) {Util::throwInvalidArgument("Error: Out of range parameter j in getProfitMatrix");}
return profitMatrix[i][j];
}

double DataGAP::getWeightMatrix(int i, int j) const {
if (i >= numTasks) {Util::throwInvalidArgument("Error: Out of range parameter i in getWeightMatrix");}
else if (j >= numVariables) {Util::throwInvalidArgument("Error: Out of range parameter j in getWeightMatrix");}
return weightMatrix[i][j];
}






Loading