Skip to content

Commit

Permalink
add madnlp
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillis committed Jul 11, 2024
1 parent e1f6535 commit a447778
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ add_subdirectory(worhp)
add_subdirectory(hsl)
add_subdirectory(snopt)
add_subdirectory(bqpd)
add_subdirectory(madnlp)
74 changes: 74 additions & 0 deletions madnlp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
cmake_minimum_required(VERSION 3.10)

project(madnlp
LANGUAGES CXX)

set(INSTALL_PREFIX "")

get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set(INSTALL_PREFIX "${PROJECT_NAME}/")
endif()

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

add_library(madnlp SHARED src/madnlp.cpp include/madnlp.h)

if(WIN32)
set_target_properties(madnlp PROPERTIES PREFIX "" IMPORT_PREFIX "")
endif()

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(NBITS_TWO "32")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(NBITS_TWO "64")
endif()

set(ARCHIVE_DIR lib)
set(RUNTIME_DIR bin)

if(${CMAKE_GENERATOR} MATCHES "Visual Studio*")
set(ARCHIVE_DIR extern/lib/win${NBITS_TWO}/microsoft)
set(RUNTIME_DIR bin/win${NBITS_TWO})
elseif(${CMAKE_GENERATOR} MATCHES "MSYS Makefiles")
set(ARCHIVE_DIR extern/lib/win${NBITS_TWO}/mingw${NBITS_TWO})
set(RUNTIME_DIR bin/win${NBITS_TWO})
endif()


install(TARGETS madnlp EXPORT madnlpTargets
LIBRARY DESTINATION ${INSTALL_PREFIX}lib
ARCHIVE DESTINATION ${INSTALL_PREFIX}lib
RUNTIME DESTINATION ${INSTALL_PREFIX}bin
INCLUDES DESTINATION ${INSTALL_PREFIX}include)

target_include_directories(madnlp PUBLIC
$<BUILD_INTERFACE:${madnlp_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INSTALL_PREFIX}include>
)

install(DIRECTORY include/ DESTINATION ${INSTALL_PREFIX}include)

install(EXPORT madnlpTargets
FILE madnlpTargets.cmake
NAMESPACE madnlp::
DESTINATION cmake
)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/madnlpConfigVersion.cmake
VERSION 13.1
COMPATIBILITY SameMajorVersion
)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION
cmake)



install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/madnlpConfigVersion.cmake"
DESTINATION cmake
)
4 changes: 4 additions & 0 deletions madnlp/cmake/madnlp-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
107 changes: 107 additions & 0 deletions madnlp/include/madnlp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#ifndef _MADNLPCINTERFACE_H
#define _MADNLPCINTERFACE_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h>

/* Symbol visibility in DLLs */
#ifndef MADNLP_SYMBOL_EXPORT
#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
#if defined(STATIC_LINKED)
#define MADNLP_SYMBOL_EXPORT
#else
#define MADNLP_SYMBOL_EXPORT __declspec(dllexport)
#endif
#elif defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
#define MADNLP_SYMBOL_EXPORT __attribute__((visibility("default")))
#else
#define MADNLP_SYMBOL_EXPORT
#endif
#endif


#define madnlp_int int
#define madnlp_real double

// structs
struct MadnlpCSolver;
struct MadnlpCStats;
struct MadnlpCDims;
struct MadnlpCInterface;

// function pointer types
typedef madnlp_int (*MadnlpCGetDim)(void* user_data);
typedef madnlp_int (*MadnlpCGetDouble)(double*, void* user_data);

typedef madnlp_int (*MadnlpCFullEvalObj)(const double*, double *, void*);
typedef madnlp_int (*MadnlpCFullEvalConstr)(const double*, double *, void*);
typedef madnlp_int (*MadnlpCFullEvalObjGrad)(const double*, double*, void*);
typedef madnlp_int (*MadnlpCFullEvalConstrJac)(const double*, double*, void*);
typedef madnlp_int (*MadnlpCFullEvalLagHess)(double, const double*, const double*, double*, void*);


struct MadnlpCDims {
size_t nw;
size_t nc;
};

struct MadnlpCStats {
double compute_sd_time;
double duinf_time;
double eval_hess_time;
double eval_jac_time;
double eval_cv_time;
double eval_grad_time;
double eval_obj_time;
double initialization_time;
double time_total;
int eval_hess_count;
int eval_jac_count;
int eval_cv_count;
int eval_grad_count;
int eval_obj_count;
int iterations_count;
int return_flag;
};

struct MadnlpCInterface {
/// @brief number of variables
MadnlpCGetDim get_nw;
/// @brief number of equality constraints
MadnlpCGetDim get_nc;

MadnlpCFullEvalLagHess full_eval_lag_hess;
MadnlpCFullEvalConstrJac full_eval_constr_jac;
MadnlpCFullEvalConstr full_eval_constr;
MadnlpCFullEvalObjGrad full_eval_obj_grad;
MadnlpCFullEvalObj full_eval_obj;

void* user_data;
};

MADNLP_SYMBOL_EXPORT void madnlp_c_startup(int, char**);
MADNLP_SYMBOL_EXPORT struct MadnlpCSolver* madnlp_c_create(struct MadnlpCInterface* nlp_interface);
MADNLP_SYMBOL_EXPORT void madnlp_c_init(struct MadnlpCSolver* s);
MADNLP_SYMBOL_EXPORT void madnlp_c_update_cco_indexes(struct MadnlpCSolver* s);
MADNLP_SYMBOL_EXPORT madnlp_int madnlp_c_solve(struct MadnlpCSolver*);

/* -1 for not found, 0 for double, 1 for int, 2 for bool, 3 for string */
MADNLP_SYMBOL_EXPORT int madnlp_c_option_type(const char* name);
MADNLP_SYMBOL_EXPORT int madnlp_c_set_option_double(struct MadnlpCSolver* s, const char* name, double val);
MADNLP_SYMBOL_EXPORT int madnlp_c_set_option_bool(struct MadnlpCSolver* s, const char* name, int val);
MADNLP_SYMBOL_EXPORT int madnlp_c_set_option_int(struct MadnlpCSolver* s, const char* name, int val);
MADNLP_SYMBOL_EXPORT int madnlp_c_set_option_string(struct MadnlpCSolver* s, const char* name, const char* val);

MADNLP_SYMBOL_EXPORT const struct MadnlpCDims* madnlp_c_get_dims(struct MadnlpCSolver* s);
MADNLP_SYMBOL_EXPORT const struct MadnlpCStats* madnlp_c_get_stats(struct MadnlpCSolver* s);
MADNLP_SYMBOL_EXPORT void madnlp_c_destroy(struct MadnlpCSolver*);
MADNLP_SYMBOL_EXPORT void madnlp_c_shutdown(void);

#ifdef __cplusplus
}
#endif

#endif // _MADNLPCINTERFACE_H
19 changes: 19 additions & 0 deletions madnlp/src/madnlp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "madnlp.h"

MADNLP_SYMBOL_EXPORT void madnlp_c_startup(int, char**) { }
MADNLP_SYMBOL_EXPORT struct MadnlpCSolver* madnlp_c_create(struct MadnlpCInterface* nlp_interface) { return 0; }
MADNLP_SYMBOL_EXPORT void madnlp_c_init(struct MadnlpCSolver* s) { }
MADNLP_SYMBOL_EXPORT void madnlp_c_update_cco_indexes(struct MadnlpCSolver* s) { }
MADNLP_SYMBOL_EXPORT madnlp_int madnlp_c_solve(struct MadnlpCSolver*) { return 0; }

/* -1 for not found, 0 for double, 1 for int, 2 for bool, 3 for string */
MADNLP_SYMBOL_EXPORT int madnlp_c_option_type(const char* name) { return 0; }
MADNLP_SYMBOL_EXPORT int madnlp_c_set_option_double(struct MadnlpCSolver* s, const char* name, double val) { return 0; }
MADNLP_SYMBOL_EXPORT int madnlp_c_set_option_bool(struct MadnlpCSolver* s, const char* name, int val) { return 0; }
MADNLP_SYMBOL_EXPORT int madnlp_c_set_option_int(struct MadnlpCSolver* s, const char* name, int val) { return 0; }
MADNLP_SYMBOL_EXPORT int madnlp_c_set_option_string(struct MadnlpCSolver* s, const char* name, const char* val) { return 0; }

MADNLP_SYMBOL_EXPORT const struct MadnlpCDims* madnlp_c_get_dims(struct MadnlpCSolver* s) { return 0; }
MADNLP_SYMBOL_EXPORT const struct MadnlpCStats* madnlp_c_get_stats(struct MadnlpCSolver* s) { return 0; }
MADNLP_SYMBOL_EXPORT void madnlp_c_destroy(struct MadnlpCSolver*) { }
MADNLP_SYMBOL_EXPORT void madnlp_c_shutdown(void) { }

0 comments on commit a447778

Please sign in to comment.