Re: [Help-glpk] Thread Safety of GLPK
Heinrich, looking at the thread example I added the glp_config("TLS”) check and I was getting a undefined reference which made me realized that for some reason I was linking to a wrong and old GLPK library instead of the one manually compiled by me. So it’s all good now. Thanks for your help! Best, Simone > On Aug 30, 2017, at 12:04, Heinrich Schuchardt wrote: > > On 08/30/2017 07:23 PM, Simone Atzeni wrote: >> Hi Heinrich, >> >> you mean the line: >> >> std::string filename = "ilp_problem" + std::to_string(rand()) + ".lp”; >> >> or the problem name: >> >> glp_set_prob_name(mip, "overlap”); >> >> The filename is not used at all in the function, it was just something I >> forgot to remove. > > Sorry I got that wrong. > > Giving the problem the same name should not be a problem because the > name is in thread local memory. > > Please, add the error catching code as in the example code. > > If this catches your error you should be able identify the responsible > line of code by setting a variable after each line and writing it to the > console in the error hook function. > > Regards > > Heinrich > > >> >> Thanks, >> Simone >> >> >>> On Aug 30, 2017, at 11:05, Heinrich Schuchardt wrote: >>> >>> Hello Simone, >>> >>> in your program all threads create random file names that are generated >>> from the same name space. The initial value of the random number >>> generator probably will be the same for all threads. This will lead to >>> two threads trying to write the same file. >>> >>> Either use a Singleton for the file name creation or use separate >>> namespaces by refering to the thread id like: >>> solution--counter.txt >>> >>> Your code lacks proper error handling for errors. >>> >>> You should path unique filenames to the threads. >>> >>> Please, have a look at glpk-4.63/examples/threads. It shows how to >>> handle GLPK errors in multithreaded applications. >>> >>> The example code creates one thread per problem. In a real world program >>> you should use a thread pool. >>> >>> Best regards >>> >>> Heinrich Schuchardt >>> >>> >>> On 08/30/2017 05:51 AM, Simone Atzeni wrote: >>>> Hi all, >>>> >>>> thanks for your answers. >>>> I updated to version 4.63, but I keep getting errors such as "segmentation >>>> fault" or "glp_free: memory allocation error”. >>>> >>>> I have a function, with a few parameters in input, which creates the MIP >>>> and solve it (attached the function which creates the MIP). >>>> This function is called by multiple threads with different parameters and >>>> they do not share any data. >>>> As soon as I call the function within a mutex lock/unlock everything works >>>> fine. >>>> >>>> I compiled the GLPK package with Clang/LLVM 4.9 which has support for TLS, >>>> so I think everything should be fine. >>>> Do I need to do something else to make GLPK thread safe? >>>> >>>> Thanks. >>>> Best, >>>> Simone >> >> ___ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] Thread Safety of GLPK
Hi Heinrich, you mean the line: std::string filename = "ilp_problem" + std::to_string(rand()) + ".lp”; or the problem name: glp_set_prob_name(mip, "overlap”); The filename is not used at all in the function, it was just something I forgot to remove. Thanks, Simone > On Aug 30, 2017, at 11:05, Heinrich Schuchardt wrote: > > Hello Simone, > > in your program all threads create random file names that are generated > from the same name space. The initial value of the random number > generator probably will be the same for all threads. This will lead to > two threads trying to write the same file. > > Either use a Singleton for the file name creation or use separate > namespaces by refering to the thread id like: > solution--counter.txt > > Your code lacks proper error handling for errors. > > You should path unique filenames to the threads. > > Please, have a look at glpk-4.63/examples/threads. It shows how to > handle GLPK errors in multithreaded applications. > > The example code creates one thread per problem. In a real world program > you should use a thread pool. > > Best regards > > Heinrich Schuchardt > > > On 08/30/2017 05:51 AM, Simone Atzeni wrote: >> Hi all, >> >> thanks for your answers. >> I updated to version 4.63, but I keep getting errors such as "segmentation >> fault" or "glp_free: memory allocation error”. >> >> I have a function, with a few parameters in input, which creates the MIP and >> solve it (attached the function which creates the MIP). >> This function is called by multiple threads with different parameters and >> they do not share any data. >> As soon as I call the function within a mutex lock/unlock everything works >> fine. >> >> I compiled the GLPK package with Clang/LLVM 4.9 which has support for TLS, >> so I think everything should be fine. >> Do I need to do something else to make GLPK thread safe? >> >> Thanks. >> Best, >> Simone ___ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] Thread Safety of GLPK
Yes, I run the following command: "../configure --prefix=$HOME/usr --with-gmp” attached the output of “config”. I am working on a Red Hat Enterprise Linux Server release 7.3. Thanks. Simone ../configure --prefix=$HOME/usr --with-gmp checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for style of include used by make... GNU checking dependency style of gcc... gcc3 checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking how to print strings... printf checking for a sed that does not truncate output... /usr/bin/sed checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for fgrep... /usr/bin/grep -F checking for ld used by gcc... /usr/tce/bin/ld checking if the linker (/usr/tce/bin/ld) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B checking the name lister (/usr/bin/nm -B) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 3458764513820540925 checking whether the shell understands some XSI constructs... yes checking whether the shell understands "+="... yes checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop checking for /usr/tce/bin/ld option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for dlltool... no checking how to associate runtime and link libraries... printf %s\n checking for ar... ar checking for archiver @FILE support... @ checking for strip... strip checking for ranlib... ranlib checking command to parse /usr/bin/nm -B output from gcc object... ok checking for sysroot... no checking for mt... mt checking if mt is a manifest tool... no checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking for objdir... .libs checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -fPIC -DPIC checking if gcc PIC flag -fPIC -DPIC works... yes checking if gcc static flag -static works... yes checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.o... (cached) yes checking whether the gcc linker (/usr/tce/bin/ld -m elf_x86_64) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes checking for exp in -lm... yes checking sys/time.h usability... yes checking sys/time.h presence... yes checking for sys/time.h... yes checking for gettimeofday... yes checking gmp.h usability... yes checking gmp.h presence... yes checking for gmp.h... yes checking whether to use GNU MP bignum library... yes checking whether to enable shared library support... no checking whether to enable MathProg ODBC support... no checking whether to enable MathProg MySQL support... no checking whether to enable reentrancy support... yes checking for thread local storage (TLS) class specifier... _Thread_local checking if libtool needs -no-undefined flag to build shared libraries... no checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating src/Makefile config.status: creating examples/Makefile config.status: creating Makefile config.status: creating config.h config.status: executing depfiles commands config.status: executing libtool commands > On Aug 30, 2017, at 00:52, Andrew Makhorin wrote: > >> thanks for your answers. >> I updated to version 4.63, but I keep getting errors such as >> "segmentation fault" or "glp_free: memory allocation error”. >> >> I h
Re: [Help-glpk] Thread Safety of GLPK
Hi all, thanks for your answers. I updated to version 4.63, but I keep getting errors such as "segmentation fault" or "glp_free: memory allocation error”. I have a function, with a few parameters in input, which creates the MIP and solve it (attached the function which creates the MIP). This function is called by multiple threads with different parameters and they do not share any data. As soon as I call the function within a mutex lock/unlock everything works fine. I compiled the GLPK package with Clang/LLVM 4.9 which has support for TLS, so I think everything should be fine. Do I need to do something else to make GLPK thread safe? Thanks. Best, Simone bool solve_mip(MyData *node1, struct MyData *node2) { glp_prob *mip; int ia[1+4], ja[1+4]; double ar[1+4], z, x1, x2, size1, size2; bool res = false; mip = glp_create_prob(); glp_set_prob_name(mip, "overlap"); glp_set_obj_dir(mip, GLP_MIN); glp_add_rows(mip, 1); glp_set_row_name(mip, 1, "c0"); long int diff = node1->start - node2->start; glp_set_row_bnds(mip, 1, GLP_FX, -1 * diff, -1 * diff); glp_add_cols(mip, 4); glp_set_col_name(mip, 1, "x1"); glp_set_col_bnds(mip, 1, GLP_DB, 0.0, node1->count); glp_set_obj_coef(mip, 1, node1->diff); glp_set_col_kind(mip, 1, GLP_IV); glp_set_col_name(mip, 2, "x2"); glp_set_col_bnds(mip, 2, GLP_DB, 0.0, node2->count); glp_set_obj_coef(mip, 2, node2->diff); glp_set_col_kind(mip, 2, GLP_IV); glp_set_col_name(mip, 3, "size1"); glp_set_col_bnds(mip, 3, GLP_DB, 0.0, (1 << (node1->size_type >> 4)) - 1); glp_set_col_kind(mip, 3, GLP_IV); glp_set_col_name(mip, 4, "size2"); glp_set_col_bnds(mip, 4, GLP_DB, 0.0, (1 << (node2->size_type >> 4)) - 1); glp_set_col_kind(mip, 4, GLP_IV); ia[1] = 1, ja[1] = 1, ar[1] = node1->diff; ia[2] = 1, ja[2] = 2, ar[2] = node2->diff; ar[2] *= -1; ia[3] = 1, ja[3] = 3, ar[3] = 1.0; ia[4] = 1, ja[4] = 4, ar[4] = -1.0; glp_load_matrix(mip, 4, ia, ja, ar); std::string filename = "ilp_problem" + std::to_string(rand()) + ".lp"; glp_iocp parm; glp_init_iocp(&parm); parm.presolve = GLP_ON; glp_term_out(GLP_OFF); glp_intopt(mip, &parm); int ret = glp_mip_status(mip); if(ret != GLP_NOFEAS) res = true; glp_delete_prob(mip); glp_free_env(); return res; } > On Aug 25, 2017, at 01:13, Andrew Makhorin wrote: > > >> In the GLPK documentation, paragraph "2.1.3 Thread Safety" states: >> >> >> "The standard version of GLPK API is not thread safe and therefore >> should not be used in multi-threaded programs.” > > The *standard* (i.e. ANSI C89) version is not thread safe. However, > starting from 4.61 (released on Jan 2017) glpk can be used in > multi-threaded programs on some platforms (including GNU/Linux and MS > Windows); for more details please see: > https://lists.gnu.org/archive/html/help-glpk/2017-01/msg00111.html . > (It's better to use the most recent version, which is 4.63.) ___ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk
[Help-glpk] Thread Safety of GLPK
Hi, In the GLPK documentation, paragraph "2.1.3 Thread Safety" states: "The standard version of GLPK API is not thread safe and therefore should not be used in multi-threaded programs.” Does it mean that two threads can not solve two independent LP/MIP simultaneously? For example, I am running a multi-threaded program where each thread is solving a different MIP, and I am experiencing a segmentation fault. I tried to analyzed the problem with GDB and looks like the seg fault is happening when one thread free the memory of its own MIP. Could the non-thread safety be the reason of the segmentation fault? I put the function call that creates and solves the MIP within a mutex lock/unlock and the segmentation fault is not happening, so I guess that answers my question. But if that’s the reason, is there a workaround or thread-safe GLPK version? The mutex reduces heavily the performance of my program. Thanks. Best Regards, Simone Simone Atzeni PhD Candidate School of Computing University of Utah _ mobile: +1 (801) 696-8373 email: sim...@cs.utah.edu <mailto:sim...@cs.utah.edu>http://www.cs.utah.edu/~simone <http://www.cs.utah.edu/~simone> ___ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] KPI simple function
Hi Xypron, I'm sorry for disturbing you again. Following your suggestion, I created this model: var Z1; var Z2; var U; maximize obj : 0.18 * Z1 + 0.82 * Z2; #maximize obj : 0.5 * Z1 + 0.5 * Z2; s.t. c1 : 20 * Z1 + 110 * U <= 83; # (0.3,0.7)-(0.85,0.6) s.t. c2 : 28 * Z1 - 8 * U <= 19; # (0.85,0.6)-(0.75,0.25) s.t. c3 : 4 * Z1 + 40 * U >= 13; # (0.75,0.25)-(0.25,0.3) s.t. c4 : 80 * Z1 - 10 * U >= 17; # (0.25,0.3)-(0.3,0.7) s.t. c5 : 40 * Z2 - 5 * U >= 9; # (0.25,0.2)-(0.3,0.6) s.t. c6 : 30 * Z2 - 110 * U >= - 57; # (0.3,0.6)-(0.85,0.75) s.t. c7 : 80 * Z2 - 20 * U <= 53; # (0.85,0.75)-(0.75,0.35) s.t. c8 : 12 * Z2 - 40 * U <= -5; # (0.75,0.35)-(0.25,0.2) solve; printf "U =%6.3f, Z1 = %6.3f, Z2 = %6.3f\n", U, Z1, Z2; end; When I try to solve this problem I get the same solution whatever is the objective function, but I need that when I change the objective function the result is different. The real problem is this: U is an action and Z1 and Z2 are two KPIs that depend on U. I'm looking for just a model to represent this in a simple way to finish my project. Sadly, I don't have the real KPI. Thanks Simone On 23/ott/09, at 19:31, xypron wrote: Hello Simone, There was a typo s.t. c4 : y >=0; # (3,0)-(0,0) Best regards Xypron xypron wrote: Hello Simone, if the solution of a linear program is unique, it will always be in a vertex of the convex polyeder described by the constraints. The objective function gives the optimization direction and hence decides which vertex of the polygon is the solution. For a two dimensional problem lets think of an polygon given by the following vertices: (0,0) (1,1) (2,1) (3,0) This corresponds to the following inequalities: s.t. c1 : x - y >= 0; # (0,0)-(1,1) s.t. c2 : y <= 1; # (1,1)-(2,1) s.t. c3 : x + y <= 3; # (2,1)-(3,0) s.t. c4 : x >=0; # (3,0)-(0,0) If our optimization direction is (1,1) the objective is maximize obj : x + y; The solution is vertex (2,1) If our optimization direction is (-1,1) the objective is maximize obj: -x + y; The solution is vertex (1,1); The complete model is: var x; var y; # uncomment the appropriate objective #maximize obj : x + y; # direction (1,1); maximize obj : -x + y; # direction (-1,1); s.t. c1 : x - y >= 0; # (0,0)-(1,1) s.t. c2 : y <= 1; # (1,1)-(2,1) s.t. c3 : x + y <= 3; # (2,1)-(3,0) s.t. c4 : x >=0; # (3,0)-(0,0) solve; printf "x = %6.3f, y = %6.3f\n", x, y; end; Best regards Xypron Simone Atzeni wrote: Hi all, I'm looking for two functions that could represent simple KPIs. In other world, I would like two MILP, in this way: MILP 1: MAX J = 0.5 * Z1 + 0.5 * Z2 Z1 = -AX + C Z2 = BX + D and MILP 2: MAX J = 0.32 * Z1 + 0.68 * Z2 Z1 = -AX + C Z2 = BX + D Z1 and Z2 are the values of the KPI and they depend on X. The constraints should be equal but the results (the values of Z1 and Z2) should be different changing the coefficients fo the objective function, in this case (0.5 - 0.5) for the MILP1 and (0.32 - 0.68) for the MILP 2. I can't find a good function. I need just functions where Z1 and Z2 depend on X but changing the coefficients in the objective functions change the values of Z1, Z2 and X. MILPs I'm using are the follow: MAX J = 0.5 Z.1 + 0.5 Z.2 Z.1 = 5X (0.196116135138184 Z.1 - 0.98058067569092 U.1 <= 0) (the equations have been normalized) Z.2 = -3X + 4 (0.196116135138184 Z.2 + 0.115384615384615 U.1 <= 0.153846153846154) and MAX J = 0.32 Z.1 + 0.68 Z.2 Z.1 = 5X Z.2 = -3X + 4 This is the picture of the two functions: Both MILPs have the same solution. Z.1 = 1 Z.2 = 0.666795 X = 0.2 In this case the weights, (0.5 - 0.5) for the MILP1 and (0.32 - 0.68) for the MILP 2, don't influence the results of the MILP. I want something in a way that the weights influence the results, so that the two MILPs have different result but they should being equal. Can someone help me? Thanks Simone ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk -- View this message in context: http://www.nabble.com/KPI-simple-function-tp26025826p26030427.html Sent from the Gnu - GLPK - Help mailing list archive at Nabble.com. ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
[Help-glpk] KPI simple function
Hi all,I'm looking for two functions that could represent simple KPIs.In other world, I would like two MILP, in this way:MILP 1:MAX J = 0.5 * Z1 + 0.5 * Z2Z1 = -AX + CZ2 = BX + DandMILP 2:MAX J = 0.32 * Z1 + 0.68 * Z2Z1 = -AX + CZ2 = BX + DZ1 and Z2 are the values of the KPI and they depend on X. The constraints should be equal but the results (the values of Z1 and Z2) should be different changing the coefficients fo the objective function, in this case (0.5 - 0.5) for the MILP1 and (0.32 - 0.68) for the MILP 2.I can't find a good function. I need just functions where Z1 and Z2 depend on X but changing the coefficients in the objective functions change the values of Z1, Z2 and X.MILPs I'm using are the follow:MAX J = 0.5 Z.1 + 0.5 Z.2Z.1 = 5X (0.196116135138184 Z.1 - 0.98058067569092 U.1 <= 0) (the equations have been normalized)Z.2 = -3X + 4 (0.196116135138184 Z.2 + 0.115384615384615 U.1 <= 0.153846153846154)andMAX J = 0.32 Z.1 + 0.68 Z.2Z.1 = 5XZ.2 = -3X + 4This is the picture of the two functions:Both MILPs have the same solution.Z.1 = 1Z.2 = 0.666795X = 0.2In this case the weights, (0.5 - 0.5) for the MILP1 and (0.32 - 0.68) for the MILP 2, don't influence the results of the MILP. I want something in a way that the weights influence the results, so that the two MILPs have different result but they should being equal.Can someone help me?ThanksSimone___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
[Help-glpk] Simple KPI Functions
Hi all, I'm looking for two functions that could represent simple KPIs. In other world, I would like two MILP, in this way: MILP 1: MAX J = 0.5 * Z1 + 0.5 * Z2 Z1 = -AX + C Z2 = BX + D and MILP 2: MAX J = 0.32 * Z1 + 0.68 * Z2 Z1 = -AX + C Z2 = BX + D Z1 and Z2 are the values of the KPI and they depend on X. The constraints should be equal but the results (the values of Z1 and Z2) should be different changing the coefficients fo the objective function, in this case (0.5 - 0.5) for the MILP1 and (0.32 - 0.68) for the MILP 2. I can't find a good function. I need just functions where Z1 and Z2 depend on X but changing the coefficients in the objective functions change the values of Z1, Z2 and X. Thank you for your help Simone ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
[Help-glpk] MIP Problem
Hi all, I'm trying to solve this simple problem: \* Problem: Unknown *\ Maximize obj: + 0.8 Z.1 + 0.2 Z.2 Subject To r.1: - Z.1 + U.1 <= 0.1 r.2: - Z.1 + U.1 >= -0.1 r.3: + Z.1 + U.1 <= 1 r.4: + Z.1 + U.1 >= 0.7 r.5: - Z.2 + U.1 <= 0.5 r.6: - Z.2 + U.1 >= 0.125 r.7: + Z.2 + U.1 <= 0.75 r.8: + Z.2 + U.1 >= 0.34 Bounds 0 <= Z.1 <= 1 0 <= Z.2 <= 1 0 <= U.1 <= 1 Generals Z.1 Z.2 U.1 End If I try to solve it from a C program using the simplex method it finds this solution: Z.1 = 0.55 Z.2 = 0.3 U.1 = 0.388977 But if I try to solve it using the command: glpsol --simplex --cpxlp program_name.txt it says: glp_read_lp: reading problem data from `mip.txt'... glp_read_lp: 8 rows, 3 columns, 16 non-zeros glp_read_lp: 3 integer columns, all of which are binary glp_read_lp: 26 lines were read ipp_basic_tech: 0 row(s) and 0 column(s) removed PROBLEM HAS NO PRIMAL FEASIBLE SOLUTION Time used: 0.0 secs Memory used: 0.0 Mb (35140 bytes) It says that the variable are integer but they should not be integer. Anyone could help me? What's wrong with it? Thanks Simone ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
[Help-glpk] Transforming a Piecewise Linear Functions in a Convex Predicate
Hi, I need to transform a Piecewise Linear Functions in a Convex Predicate. In attachment there is a tex file with the function and my transformation in a convex predicate. Using that convex predicate in a milp, the milp does not found solution. So in attachment there is my .c file with the function that create the MILP and an output with a milp with random valute. The function in the examples is repeated two times, but it does not matter. I don't know where is my mistake. It's impossible for me find it. Thank you for your help. Cheers Simone Piecewise-Linear-Functions.tex Description: Binary data function.c Description: Binary data Maximize obj: 0.5 Z.1 + 0.5 Z.2 Subject To r.1: + 5.6 U.1 -1 Z.1 + 72.8 Y.1.1 <= 56 r.2: -5.6 U.1 + 1 Z.1 -15.8 Y.1.1 <= 1 r.3: + 1 U.1 + 10 Q.1 <= 10 r.4: -1 U.1 + 1 Q.2 <= 0 r.5: - 1 Q.1 - 1 Q.2 - 1 Y.1.1 <= -1 r.6: + 5.6 U.1 -1 Z.1 + 72.8 Y.1.2 <= 56 r.7: -5.6 U.1 + 1 Z.1 -15.8 Y.1.2 <= 1 r.8: + 1 U.1 + 9 Q.3 <= 10 r.9: -1 U.1 + 2 Q.4 <= 0 r.10: - Q.3 - Q.4 - Y.1.2 <= -1 r.11: + 5.6 U.1 -1 Z.1 + 72.8 Y.1.3 <= 56 r.12: -5.6 U.1 + 1 Z.1 -15.8 Y.1.3 <= 1 r.13: -8 Y.1.3 + 1 U.1 <= 2 r.14: + 11.2 U.1 -1 Z.2 + 128.8 Y.1.1 <= 112 r.15: -11.2 U.1 + 1 Z.2 -15.8 Y.1.1 <= 1 r.16: + 1 U.1 + 10 Q.1 <= 10 r.17: -1 U.1 + 1 Q.2 <= 0 r.18: - 1 Q.1 - 1 Q.2 - 1 Y.1.1 <= -1 r.19: + 0 U.1 -1 Z.2 + 28 Y.1.2 <= 0 r.20: + 0 U.1 + 1 Z.2 -27 Y.1.2 <= 1 r.21: + 1 U.1 + 9 Q.3 <= 10 r.22: -1 U.1 + 2 Q.4 <= 0 r.23: - Q.3 - Q.4 - Y.1.2 <= -1 r.24: + 5.6 U.1 -1 Z.2 + 72.8 Y.1.3 <= 56 r.25: -5.6 U.1 + 1 Z.2 -15.8 Y.1.3 <= 1 r.26: -8 Y.1.3 + 1 U.1 <= 2 r.27: Y.1.1 + Y.1.2 + Y.1.3 = 1 Bounds 0 <= Z.1 <= 1 0 <= Z.2 <= 1 0 <= U.1 <= 10 0 <= Y.1.1 <= 1 0 <= Q.1 <= 1 0 <= Q.2 <= 1 0 <= Y.1.2 <= 1 0 <= Q.3 <= 1 0 <= Q.4 <= 1 0 <= Y.1.3 <= 1 Generals Z.1 Z.2 U.1 Integer Y.1.1 Y.1.2 Y.1.3 Q.1 Q.2 Q.3 Q.4 End ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
[Help-glpk] Piecewise Linear Function
Hi, I have a piecewise linear function like this: \[ h_i({\bf x},{\bf u})= \begin{cases} A_1({\bf x}) + {\bf u} (B_1({\bf x}) - A_1({\bf x})), \text{se $0 \le {\bf u} < 1$} \\ B_1({\bf x}) + ({\bf u}-1) (B_2({\bf x}) - B_1({\bf x})), \text{se $1 \le {\bf u} < 2$} \\ B_2({\bf x}) + ({\bf u}-2) (B_3({\bf x}) - B_2({\bf x})), \text{se ${\bf u} \ge 2$} \\ \end{cases} \] where: \begin{itemize} \item $A_1({\bf x}) = 3x$ \item $B_1({\bf x}) = 4x$ \item $B_2({\bf x}) = 5x$ \item $B_3({\bf x}) = 6x$ \end{itemize} This function represents the constraints in a MILP. To solve this MILP I have to convex my function, but I don't know like do it. Somebody can help me? Thanks Simone Hi,I have a piecewise linear function like this:\[ h_i({\bf x},{\bf u})= \begin{cases} A_1({\bf x}) + {\bf u} (B_1({\bf x}) - A_1({\bf x})), & \text{se $0 \le {\bf u} < 1$} \\ B_1({\bf x}) + ({\bf u}-1) (B_2({\bf x}) - B_1({\bf x})), & \text{se $1 \le {\bf u} < 2$} \\ B_2({\bf x}) + ({\bf u}-2) (B_3({\bf x}) - B_2({\bf x})), & \text{se ${\bf u} \ge 2$} \\ \end{cases} \] where:\begin{itemize} \item $A_1({\bf x}) = 3x$\item $B_1({\bf x}) = 4x$\item $B_2({\bf x}) = 5x$\item $B_3({\bf x}) = 6x$\end{itemize} This function represents the constraints in a MILP.To solve this MILP I have to convex my function, but I don't know like do it.Somebody can help me?ThanksSimone ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
[Help-glpk] Absolute Value in Objective Function
Hi, I have a problem. My objective function is (in LaTex): minimize: \delta + \sum_{\tau=t-k+1}^t \lvert\lvert {\bf a}(t+1) - {\bf a}(\tau) \rvert\rvert where: a(t+1): my variables (a is a vector) a(\tau): coefficients (a is a verctor of coefficients) \delta: coefficient but I haven't any idea to write it in GLPK (API for C). Someone could help me? Thanks Simone ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
[Help-glpk] Constraints Problem
Hi,I have a problem with GLPK. I had written a program like this: lpx_set_prob_name(lp,"SAPP"); lpx_set_obj_dir(lp,LPX_MIN); lpx_add_rows(lp,1); lpx_add_cols(lp,4); lpx_set_col_kind(lp,1,LPX_IV); lpx_set_col_name(lp,1,"V1"); lpx_set_col_bnds(lp,1,LPX_DB,0.0,1.0); lpx_set_col_kind(lp,2,LPX_IV); lpx_set_col_name(lp,2,"V2"); lpx_set_col_bnds(lp,2,LPX_DB,0.0,1.0); lpx_set_col_kind(lp,3,LPX_IV); lpx_set_col_name(lp,3,"V3"); lpx_set_col_bnds(lp,3,LPX_DB,0.0,1.0); lpx_set_col_kind(lp,4,LPX_IV); lpx_set_col_name(lp,4,"V4"); lpx_set_col_bnds(lp,4,LPX_DB,0.0,1.0); lpx_set_row_name(lp,1,"VERTEXFLOW"); lpx_set_row_bnds(lp,1,LPX_FX,0.0,0.0); ia[1] = 1, ja[1] = 1, ar[1] = 1.0; ia[2] = 1, ja[2] = 2, ar[2] = 1.0; ia[3] = 1, ja[3] = 3, ar[3] = -1.0; ia[4] = 1, ja[4] = 4, ar[4] = -1.0; lpx_load_matrix(lp,1,ia,ja,ar); Then I get the command: ... lpx_print_prob(lp,"vincoli.txt"); ... The result is: ... Row 1: VERTEXFLOW = 0 1 V1 1 V2 ... but there are not V3 and V4. What is the problem?? The program that I show in this mail is only an example, but the real program is very big. It has about 1500 variables and 300 constraints, so I have the same problem about several constraints. Can you help me? Sorry for my bad english :-D Thanks. Simone Atzeni Hi,I have a problem with GLPK.I had written a program like this:lpx_set_prob_name(lp,"SAPP");lpx_set_obj_dir(lp,LPX_MIN);lpx_add_rows(lp,1);lpx_add_cols(lp,4);lpx_set_col_kind(lp,1,LPX_IV);lpx_set_col_name(lp,1,"V1");lpx_set_col_bnds(lp,1,LPX_DB,0.0,1.0);lpx_set_col_kind(lp,2,LPX_IV);lpx_set_col_name(lp,2,"V2");lpx_set_col_bnds(lp,2,LPX_DB,0.0,1.0);lpx_set_col_kind(lp,3,LPX_IV);lpx_set_col_name(lp,3,"V3");lpx_set_col_bnds(lp,3,LPX_DB,0.0,1.0);lpx_set_col_kind(lp,4,LPX_IV);lpx_set_col_name(lp,4,"V4");lpx_set_col_bnds(lp,4,LPX_DB,0.0,1.0);lpx_set_row_name(lp,1,"VERTEXFLOW");lpx_set_row_bnds(lp,1,LPX_FX,0.0,0.0);ia[1] = 1, ja[1] = 1, ar[1] = 1.0;ia[2] = 1, ja[2] = 2, ar[2] = 1.0;ia[3] = 1, ja[3] = 3, ar[3] = -1.0;ia[4] = 1, ja[4] = 4, ar[4] = -1.0;lpx_load_matrix(lp,1,ia,ja,ar);Then I get the command:...lpx_print_prob(lp,"vincoli.txt");...The result is:...Row 1: VERTEXFLOW = 0 1 V1 1 V2...but there are not V3 and V4.What is the problem??The program that I show in this mail is only an example, but the real program is very big. It has about 1500 variables and 300 constraints, so I have the same problem about several constraints.Can you help me?Sorry for my bad english :-DThanks.Simone Atzeni ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk