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 <xypron.g...@gmx.de> 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 <xypron.g...@gmx.de> 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] 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 casethe 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] 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 functionrepresents 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] 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