Skip to content

Commit

Permalink
Remove lpsolve from OpenModelica. (#9047)
Browse files Browse the repository at this point in the history
  - `lpsolve` is not needed by OpenModelica anymore. It was used as one of
    the options to solve a lionear system from the scripting API. That is
    now removed and all such uses will be handled by `dgesv` instead.

  - The API function **`SolveLinearSystem`** is changed from
    ```
    function solveLinearSystem
      input Real[size(B, 1), size(B, 1)] A;
      input Real[:] B;
      input LinearSystemSolver solver = LinearSystemSolver.dgesv;
      input Integer[:] isInt = {-1} "list of indices that are integers";
      output Real[size(B, 1)] X;
      output Integer info;
    end solveLinearSystem;
    ```
    to
    ```
    function solveLinearSystem
      input Real[size(B, 1), size(B, 1)] A;
      input Real[:] B;
      output Real[size(B, 1)] X;
      output Integer info;
    end solveLinearSystem;
    ```

  - The following configuration variables are removed from autoconf
    - `LIBLPSOLVE55`
    - `LPSOLVEINCLUDE`
    - `NO_LPLIB`

  - The following configuration variables are removed from CMake
    - `OM_OMC_USE_LPSOLVE`
    - `OM_OMC_BUILD_LPSOLVE`

  - The follwong variables are removed from omc_config.h
    - `CONFIG_LPSOLVEINC`

  - `System.lpsolve55` is removed from System.mo.
  - Bootstrapping sources are updated for the change.

  - Unrelated:
    - Removed outdated README in OpenModelica/OMCompiler for CMake. There
      is a new one in OpenModelica/.
  • Loading branch information
mahge committed Jun 1, 2022
1 parent 8d9551a commit 07650dd
Show file tree
Hide file tree
Showing 30 changed files with 68 additions and 699 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/3rdParty
Submodule 3rdParty updated 162 files
3 changes: 0 additions & 3 deletions OMCompiler/CMakeLists.txt
Expand Up @@ -19,9 +19,6 @@ omc_option(OM_OMC_ENABLE_CPP_RUNTIME "Enable, build, and install the C++ simulat

omc_option(OM_OMC_USE_CORBA "Should use corba." OFF)

omc_option(OM_OMC_USE_LPSOLVE "Should we use lpsolve." OFF)
omc_option(OM_OMC_BUILD_LPSOLVE "Should we build our own 3rdParty/lpsolve." OFF)

omc_option(OM_OMC_USE_LAPACK "Should we use lapack." ON)


Expand Down
1 change: 0 additions & 1 deletion OMCompiler/COPYING
Expand Up @@ -303,7 +303,6 @@ or online http://opensource.org/licenses/LGPL-2.1.
[BSD] csv-compare Tubes.cs Copyright (c) 2013, ITI GmbH Dresden
[BSD-2-Clause] is_utf8 Copyright (c) 2013, Palard Julien
[BSD-1] Copyright (c) 2005-2013, Troy D. Hanson http://troydhanson.github.com/uthash/
[LGPL 2.1] lpsolve55
[LGPL 2.1+] Copyright (C) 2008 Robert Gamble libcsv.c
[MPL v2.0] Mozilla Public License v2.0
[Public Domain] sqlite3
Expand Down
8 changes: 2 additions & 6 deletions OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -2440,15 +2440,11 @@ Returns a list of names of libraries and their path on the system, for example:
</html>"));
end getLoadedLibraries;

type LinearSystemSolver = enumeration(dgesv,lpsolve55);
function solveLinearSystem
"Solve A*X = B, using dgesv or lp_solve (if any variable in X is integer)
Returns for solver dgesv: info>0: Singular for element i. info<0: Bad input.
For solver lp_solve: ???"
"Solve A*X = B using dgesv.
Returns for solver dgesv: info>0: Singular for element i. info<0: Bad input."
input Real[size(B,1),size(B,1)] A;
input Real[:] B;
input LinearSystemSolver solver = LinearSystemSolver.dgesv;
input Integer[:] isInt = {-1} "list of indices that are integers";
output Real[size(B,1)] X;
output Integer info;
external "builtin";
Expand Down
8 changes: 2 additions & 6 deletions OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo
Expand Up @@ -2682,15 +2682,11 @@ Returns a list of names of libraries and their path on the system, for example:
</html>"));
end getLoadedLibraries;

type LinearSystemSolver = enumeration(dgesv,lpsolve55);
function solveLinearSystem
"Solve A*X = B, using dgesv or lp_solve (if any variable in X is integer)
Returns for solver dgesv: info>0: Singular for element i. info<0: Bad input.
For solver lp_solve: ???"
"Solve A*X = B using dgesv.
Returns for solver dgesv: info>0: Singular for element i. info<0: Bad input."
input Real[size(B,1),size(B,1)] A;
input Real[:] B;
input LinearSystemSolver solver = LinearSystemSolver.dgesv;
input Integer[:] isInt = {-1} "list of indices that are integers";
output Real[size(B,1)] X;
output Integer info;
external "builtin";
Expand Down
9 changes: 1 addition & 8 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -3058,20 +3058,13 @@ algorithm
then
ValuesUtil.makeTuple({Values.BOOL(false),Values.STRING("")});

case ("solveLinearSystem",{Values.ARRAY(valueLst=vals),v,Values.ENUM_LITERAL(index=1 /*dgesv*/),Values.ARRAY(valueLst={Values.INTEGER(-1)})})
case ("solveLinearSystem",{Values.ARRAY(valueLst=vals),v})
equation
(realVals,i) = System.dgesv(List.map(vals,ValuesUtil.arrayValueReals),ValuesUtil.arrayValueReals(v));
v = ValuesUtil.makeArray(List.map(realVals,ValuesUtil.makeReal));
then
Values.TUPLE({v,Values.INTEGER(i)});

case ("solveLinearSystem",{Values.ARRAY(valueLst=vals),v,Values.ENUM_LITERAL(index=2 /*lpsolve55*/),Values.ARRAY(valueLst=vals2)})
equation
(realVals,i) = System.lpsolve55(List.map(vals,ValuesUtil.arrayValueReals),ValuesUtil.arrayValueReals(v),List.map(vals2,ValuesUtil.valueInteger));
v = ValuesUtil.makeArray(List.map(realVals,ValuesUtil.makeReal));
then
Values.TUPLE({v,Values.INTEGER(i)});

case ("solveLinearSystem",{_,v,_,_})
equation
Error.addMessage(Error.INTERNAL_ERROR,{"Unknown input to solveLinearSystem scripting function"});
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/SimCode/SimCodeFunctionUtil.mo
Expand Up @@ -2281,7 +2281,7 @@ algorithm
if "Windows_NT" == Autoconf.os then
// omcruntime on windows needs linking with mico2313 and wsock and then some :)
str = "-l" + str;
strs = str :: "-lintl" :: "-liconv" :: "-lexpat" :: "-lsqlite3" :: "-llpsolve55" :: "-ltre" :: "-lomniORB420_rt" :: "-lomnithread40_rt" :: "-lws2_32" :: "-lRpcrt4" :: "-lregex" :: {};
strs = str :: "-lintl" :: "-liconv" :: "-lexpat" :: "-lsqlite3" :: "-ltre" :: "-lomniORB420_rt" :: "-lomnithread40_rt" :: "-lws2_32" :: "-lRpcrt4" :: "-lregex" :: {};
else
strs = Autoconf.systemLibs;
end if;
Expand Down
4 changes: 0 additions & 4 deletions OMCompiler/Compiler/Translation/openmodelica.pot
Expand Up @@ -5034,10 +5034,6 @@ msgstr ""
msgid "Unknown uri: %s"
msgstr ""

#: ../runtime/systemimpl.c:1801
msgid "Not compiled with lpsolve support"
msgstr ""

#: ../runtime/systemimpl.c:2226
#, c-format
msgid "freopen(%s,%s,%s) failed: %s"
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/Util/Autoconf.mo.in
Expand Up @@ -26,7 +26,7 @@ encapsulated package Autoconf

constant String corbaLibs = "@CORBALIBS@";
constant String hwloc = if @WITH_HWLOC@ == 1 then "-lhwloc" else "";
constant list<String> systemLibs = {"-lomcruntime", "-lexpat", "-lsqlite3", "@LIBLPSOLVE55@", corbaLibs, "-lomcgc", hwloc};
constant list<String> systemLibs = {"-lomcruntime", "-lexpat", "-lsqlite3", corbaLibs, "-lomcgc", hwloc};

constant String triple = "@host_short@";

Expand Down
10 changes: 0 additions & 10 deletions OMCompiler/Compiler/Util/System.mo
Expand Up @@ -977,16 +977,6 @@ public function dgesv
external "C" info=SystemImpl__dgesv(A,B,X) annotation(Library = {"omcruntime","Lapack"});
end dgesv;

public function lpsolve55
"lpsolve55"
input list<list<Real>> A;
input list<Real> B;
input list<Integer> intIndices;
output list<Real> X;
output Integer info;
external "C" info=SystemImpl__lpsolve55(A,B,intIndices,X) annotation(Library = {"omcruntime"});
end lpsolve55;

public function reopenStandardStream
input Integer _stream "stdin,stdout,stderr";
input String filename;
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/boot/Makefile.in
Expand Up @@ -20,7 +20,7 @@ else
OMENCRYPTIONLIBS=
endif

LDFLAGS=-L. -L$(GEN_DIR) -L"$(OMHOME)/$(LIB_OMC)" $(LOMPARSE) $(LCOMPILERRUNTIME) -lOpenModelicaRuntimeC -lomantlr3 $(CORBALIBS) $(FMILIB_OR_BOOT) @RT_LDFLAGS@ @LIBSOCKET@ @LIBLPSOLVE55@ @OMC_LIBS@ @GRAPHLIB@ @LD_LAPACK@ -lzmq $(OMENCRYPTIONLIBS)
LDFLAGS=-L. -L$(GEN_DIR) -L"$(OMHOME)/$(LIB_OMC)" $(LOMPARSE) $(LCOMPILERRUNTIME) -lOpenModelicaRuntimeC -lomantlr3 $(CORBALIBS) $(FMILIB_OR_BOOT) @RT_LDFLAGS@ @LIBSOCKET@ @OMC_LIBS@ @GRAPHLIB@ @LD_LAPACK@ -lzmq $(OMENCRYPTIONLIBS)
LDFLAGS_SHARED_MAIN=-L"$(OMHOME)/$(LIB_OMC)" @RT_LDFLAGS_SHARED@
ifeq (@WITH_FMIL@,yes)
FMILIB = $(TOP_DIR)/3rdParty/FMIL/install/"$(LIB_OMC)"/libfmilib.a
Expand Down
3 changes: 1 addition & 2 deletions OMCompiler/Compiler/boot/Makefile.omdev.mingw
Expand Up @@ -38,10 +38,9 @@ OMENCRYPTIONLIBS=
endif
LDFLAGS=-L./ $(LOMPARSE) $(LCOMPILERRUNTIME) -L"$(OMHOME)/lib/omc" \
-lOpenModelicaRuntimeC \
-lomantlr3 -lregex -lwsock32 -llpsolve55 -luuid -lole32 -lws2_32 -limagehlp \
-lomantlr3 -lregex -lwsock32 -luuid -lole32 -lws2_32 -limagehlp \
-lRpcrt4 -lopenblas -fopenmp -lomcgc -lpthread $(FMILIB_OR_BOOT) -lshlwapi -liconv -lintl -lmetis \
-Wl,--enable-stdcall-fixup -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic -static-libgcc \
-L../../3rdParty/lpsolve/build/lib \
-lgfortran -ltre -lomniORB420_rt -lomnithread40_rt \
-lzmq \
$(OMENCRYPTIONLIBS) \
Expand Down
26 changes: 0 additions & 26 deletions OMCompiler/Compiler/boot/bootstrap-sources/build/System.c
Expand Up @@ -624,32 +624,6 @@ _success = omc_System_reopenStandardStream(threadData, tmp1, _filename);
out_success = mmc_mk_icon(_success);
return out_success;
}
modelica_metatype omc_System_lpsolve55(threadData_t *threadData, modelica_metatype _A, modelica_metatype _B, modelica_metatype _intIndices, modelica_integer *out_info)
{
modelica_metatype _A_ext;
modelica_metatype _B_ext;
modelica_metatype _intIndices_ext;
modelica_metatype _X_ext;
int _info_ext;
modelica_metatype _X = NULL;
modelica_integer _info;
_A_ext = (modelica_metatype)_A;
_B_ext = (modelica_metatype)_B;
_intIndices_ext = (modelica_metatype)_intIndices;
_info_ext = SystemImpl__lpsolve55(_A_ext, _B_ext, _intIndices_ext, &_X_ext);
_X = (modelica_metatype)_X_ext;
_info = (modelica_integer)_info_ext;
if (out_info) { *out_info = _info; }
return _X;
}
modelica_metatype boxptr_System_lpsolve55(threadData_t *threadData, modelica_metatype _A, modelica_metatype _B, modelica_metatype _intIndices, modelica_metatype *out_info)
{
modelica_integer _info;
modelica_metatype _X = NULL;
_X = omc_System_lpsolve55(threadData, _A, _B, _intIndices, &_info);
if (out_info) { *out_info = mmc_mk_icon(_info); }
return _X;
}
modelica_metatype omc_System_dgesv(threadData_t *threadData, modelica_metatype _A, modelica_metatype _B, modelica_integer *out_info)
{
modelica_metatype _A_ext;
Expand Down
7 changes: 0 additions & 7 deletions OMCompiler/Compiler/boot/bootstrap-sources/build/System.h
Expand Up @@ -285,13 +285,6 @@ static const MMC_DEFSTRUCTLIT(boxvar_lit_System_reopenStandardStream,2,0) {(void
#define boxvar_System_reopenStandardStream MMC_REFSTRUCTLIT(boxvar_lit_System_reopenStandardStream)
extern int SystemImpl__reopenStandardStream(int /*__stream*/, const char* /*_filename*/);
DLLExport
modelica_metatype omc_System_lpsolve55(threadData_t *threadData, modelica_metatype _A, modelica_metatype _B, modelica_metatype _intIndices, modelica_integer *out_info);
DLLExport
modelica_metatype boxptr_System_lpsolve55(threadData_t *threadData, modelica_metatype _A, modelica_metatype _B, modelica_metatype _intIndices, modelica_metatype *out_info);
static const MMC_DEFSTRUCTLIT(boxvar_lit_System_lpsolve55,2,0) {(void*) boxptr_System_lpsolve55,0}};
#define boxvar_System_lpsolve55 MMC_REFSTRUCTLIT(boxvar_lit_System_lpsolve55)
extern int SystemImpl__lpsolve55(modelica_metatype /*_A*/, modelica_metatype /*_B*/, modelica_metatype /*_intIndices*/, modelica_metatype* /*_X*/);
DLLExport
modelica_metatype omc_System_dgesv(threadData_t *threadData, modelica_metatype _A, modelica_metatype _B, modelica_integer *out_info);
DLLExport
modelica_metatype boxptr_System_dgesv(threadData_t *threadData, modelica_metatype _A, modelica_metatype _B, modelica_metatype *out_info);
Expand Down
8 changes: 0 additions & 8 deletions OMCompiler/Compiler/runtime/CMakeLists.txt
Expand Up @@ -79,12 +79,6 @@ target_link_libraries(omcruntime PUBLIC omc::3rd::ffi)
target_link_libraries(omcruntime PUBLIC omc::3rd::libzmq)
target_link_libraries(omcruntime PUBLIC omc::3rd::zlib)

if(OM_OMC_USE_LPSOLVE)
target_link_libraries(omcruntime PUBLIC omc::3rd::lpsolve55)
else()
target_compile_definitions(omcruntime PRIVATE NO_LPLIB)
endif()

if(OM_OMC_USE_LAPACK)
target_link_libraries(omcruntime PUBLIC ${LAPACK_LIBRARIES})
endif()
Expand Down Expand Up @@ -194,8 +188,6 @@ if(OpenMP_FOUND)
set(OMPCFLAGS "-fopenmp")
endif()

set(LPSOLVEINC "lpsolve/lp_lib.h")

if(LAPACK_FOUND)
set(HAVE_LAPACK "#define HAVE_LAPACK")
if(OMC_HAVE_LAPACK_DEPRECATED)
Expand Down
3 changes: 1 addition & 2 deletions OMCompiler/Compiler/runtime/Makefile.omdev.mingw
Expand Up @@ -25,7 +25,6 @@ FMIINCLUDE = ../../3rdParty/FMIL/install/include
GRAPHINCLUDE=../../3rdParty/metis-5.1.0/include
CJSONINCLUDE = ../../3rdParty/cJSON/
OMBUILDDIR = ../../../build
LPSOLVEINCLUDE = ../../3rdParty/lpsolve/build/include/
SQLITE3INCLUDE = ../../3rdParty/sqlite3/build/include/
ZMQINCLUDE = ../../3rdParty/libzmq/include
GCINCLUDE = -DGC_WIN32_PTHREADS -I../../3rdParty/gc/include
Expand All @@ -50,7 +49,7 @@ OMCCORBASRC = omc_communication.o omc_communication_impl.o Corba_omc.o
SHELL = /bin/sh
CC = gcc
CXX = g++
override CFLAGS += $(USE_CORBA) $(USE_METIS) -Werror=implicit-function-declaration -Wall -Wno-unused-variable -I$(OMC_CONFIG_INC) -I$(top_builddir)/SimulationRuntime/c -I$(top_builddir)/SimulationRuntime/c/simulation/results -I$(top_builddir)/SimulationRuntime/c/util -I$(top_builddir)/SimulationRuntime/c/meta -I$(top_builddir)/SimulationRuntime/c/meta/gc $(CORBAINCL) $(GCINCLUDE) -I$(FMIINCLUDE) -I$(CJSONINCLUDE) -I$(GRAPHINCLUDE) -I$(LPSOLVEINCLUDE) -I$(SQLITE3INCLUDE) -I$(ZMQINCLUDE) -I"$(TOP_DIR)/3rdParty/FMIL/ThirdParty/Zlib/zlib-1.2.6" -I"$(TOP_DIR)/3rdParty/FMIL/build/zlib/" -I"$(TOP_DIR)/3rdParty/libffi/install/include/" -DWIN32_LEAN_AND_MEAN
override CFLAGS += $(USE_CORBA) $(USE_METIS) -Werror=implicit-function-declaration -Wall -Wno-unused-variable -I$(OMC_CONFIG_INC) -I$(top_builddir)/SimulationRuntime/c -I$(top_builddir)/SimulationRuntime/c/simulation/results -I$(top_builddir)/SimulationRuntime/c/util -I$(top_builddir)/SimulationRuntime/c/meta -I$(top_builddir)/SimulationRuntime/c/meta/gc $(CORBAINCL) $(GCINCLUDE) -I$(FMIINCLUDE) -I$(CJSONINCLUDE) -I$(GRAPHINCLUDE) -I$(SQLITE3INCLUDE) -I$(ZMQINCLUDE) -I"$(TOP_DIR)/3rdParty/FMIL/ThirdParty/Zlib/zlib-1.2.6" -I"$(TOP_DIR)/3rdParty/FMIL/build/zlib/" -I"$(TOP_DIR)/3rdParty/libffi/install/include/" -DWIN32_LEAN_AND_MEAN
override CXXFLAGS += -std=c++11 $(CFLAGS)

include Makefile.common
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/runtime/Makefile.vc
Expand Up @@ -3,7 +3,7 @@

USE_CORBA = /DUSE_CORBA

INCLUDES = $(INCP) /I. /I..\..\SimulationRuntime\c\ /I..\ /I$(OMDEV)/lib/omniORB-4.2.0-msvc-10/include /Ilpsolve
INCLUDES = $(INCP) /I. /I..\..\SimulationRuntime\c\ /I..\ /I$(OMDEV)/lib/omniORB-4.2.0-msvc-10/include

CFLAGS = /O2 /Ot $(INCLUDES) /D "WIN32" /D "NDEBUG" /D "_LIB" /D "_MBCS" /FD /EHsc /MT /GS- /W2 /c /TC
CXXFLAGS = /O2 /Ot $(INCLUDES) /D "WIN32" /D "NDEBUG" /D "_LIB" /D "_MBCS" /FD /EHsc /MT /GS- /W2 /c /TP
Expand Down
55 changes: 0 additions & 55 deletions OMCompiler/Compiler/runtime/systemimpl.c
Expand Up @@ -2038,61 +2038,6 @@ int SystemImpl__dgesv(void *lA, void *lB, void **res)
}
#endif

#ifdef NO_LPLIB
int SystemImpl__lpsolve55(void *lA, void *lB, void *ix, void **res)
{
c_add_message(NULL,-1,ErrorType_scripting,ErrorLevel_error,gettext("Not compiled with lpsolve support"),NULL,0);
MMC_THROW();
}
#else

#include CONFIG_LPSOLVEINC

int SystemImpl__lpsolve55(void *lA, void *lB, void *ix, void **res)
{
int i = 0, j = 0, info, sz = 0;
void *tmp = lB;
lprec *lp;
double inf,*vres;

while (MMC_NILHDR != MMC_GETHDR(tmp)) {
sz++;
tmp = MMC_CDR(tmp);
}
vres = (double*)omc_alloc_interface.malloc_atomic(sz*sizeof(double));
memset(vres,0,sz*sizeof(double));
lp = make_lp(sz, sz);
set_verbose(lp, 1);
inf = get_infinite(lp);

for (i=0; i<sz; i++) {
set_lowbo(lp, i+1, -inf);
set_constr_type(lp, i+1, EQ);
tmp = MMC_CAR(lA);
for (j=0; j<sz; j++) {
set_mat(lp, i+1, j+1, mmc_prim_get_real(MMC_CAR(tmp)));
tmp = MMC_CDR(tmp);
}
set_rh(lp, i+1, mmc_prim_get_real(MMC_CAR(lB)));
lA = MMC_CDR(lA);
lB = MMC_CDR(lB);
}
while (MMC_NILHDR != MMC_GETHDR(ix)) {
if (MMC_UNTAGFIXNUM(MMC_CAR(ix)) != -1) set_int(lp, MMC_UNTAGFIXNUM(MMC_CAR(ix)), 1);
ix = MMC_CDR(ix);
}
info=solve(lp);
//print_lp(lp);
if (info==0 || info==1) get_ptr_variables(lp,&vres);
*res = mmc_mk_nil();
while (sz--) {
*res = mmc_mk_cons(mmc_mk_rcon(vres[sz]),*res);
}
delete_lp(lp);
return info;
}
#endif

#define MODELICAPATH_LEVELS 6
typedef struct {
const char *dir;
Expand Down

0 comments on commit 07650dd

Please sign in to comment.