******************************************************************** ******************************************************************** This chapter is from the book: Castillo, E., Conejo A.J., Pedregal, P., Garc\'{\i}a, R. and Alguacil, N. (2002). Building and Solving Mathematical Programming Models in Engineering and Science, Pure and Applied Mathematics Series, Wiley, New York. Copyright © 2002 by John Wiley and Sons, Inc. This material is used by permission of John Wiley and Sons, Inc. ******************************************************************** ******************************************************************** $title Neural networks (neural2) SETS S number of data vectors/1*30/ I dimension of data input vectors/1*2/ J number of different learning functions/1*5/ R number of basic functions/1*3/; ALIAS(S,S1) PARAMETERS X(I,S) input data vectors Y(S) output data powers(R) exponents of x in the basic functions /1 0.5 2 1 3 2/; X(I,S)=uniform(0,1)*0.5; Y(S)=sqr(0.3+0.3*X('1',S)+0.7*X('2',S))+(uniform(0,1)-0.5)*0.01; PARAMETERS aux auxiliary parameter x1 auxiliary parameter x2 auxiliary parameter x3 auxiliary parameter f1 auxiliary parameter f2 auxiliary parameter f3 auxiliary parameter ymin minimum value of Y(S) ymax maximum value of Y(S) acterror maximum prediction error maxerror maximum allowed error for the bisection method; maxerror=0.00001; VARIABLES z1 function1 to be optimized z2 function2 to be optimized z3 function3 to be optimized z4 function21 to be optimized z5 function21 to be optimized W0 threshold value W(I) weight associated with component i of input alfa(R) coefficients of the neural function; POSITIVE VARIABLES epsilon error; EQUATIONS Q1 definition of z1 Q2 definition of z2 Q3 definition of z3 Q4 definition of z4 Q5 definition of z5 const1(S) upper error bound const2(S) lower error bound const3(S) upper error bound const4(S) lower error bound normalized normalized values increasing(S,S1) the f function must be increasing; Q1..z1=e=sum(S,sqr(Y(S)-arctan(W0+sum(I,W(I)*X(I,S))))); Q2..z2=e=sum(S,sqr(W0+sum(I,W(I)*X(I,S))-sin(Y(S))/cos(Y(S)))); Q3..z3=e=epsilon; Q4..z4=e=sum(S,sqr(W0+sum(I,W(I)*X(I,S)) -sum(R,alfa(R)*Y(S)**(powers(R))))); Q5..z5=e=epsilon; const1(S)..W0+sum(I,W(I)*X(I,S))-epsilon=l=sin(Y(S))/cos(Y(S)); const2(S)..-W0-sum(I,W(I)*X(I,S))-epsilon=l=-sin(Y(S))/cos(Y(S)); const3(S)..W0+sum(I,W(I)*X(I,S)) -sum(R,alfa(R)*Y(S)**(powers(R)))-epsilon=l=0.0; const4(S)..-W0-sum(I,W(I)*X(I,S)) +sum(R,alfa(R)*Y(S)**(powers(R)))-epsilon=l=0.0; normalized..sum(R,alfa(R)*Y('1')**(powers(R)))=e=1; increasing(S,S1)$(Y(S)Y(S),ymax=Y(S)); ); loop(J, if(ord(J) eq 1, SOLVE reg1 USING nlp MINIMIZING z1; put "z1=",z1.l:12:9/;); if(ord(J) eq 2, SOLVE reg2 USING nlp MINIMIZING z2; put "z2=",z2.l:12:9/;); if(ord(J) eq 3, SOLVE reg3 USING lp MINIMIZING z3; put "z3=",z3.l:12:9/;); if(ord(J) eq 4, SOLVE reg4 USING nlp MINIMIZING z4; put "z4=",z4.l:12:9/;); if(ord(J) eq 5, SOLVE reg5 USING lp MINIMIZING z5; put "z5=",z5.l:12:9/;); put "Weights:"/; put W0.l:12:3; loop(I,put " & ",W.l(I):12:3;); put " "/; if(((ord(J) eq 4) or (ord(J) eq 5)), put "Alfas:"/; loop(R,put " & ",alfa.l(R):12:3;); put " "/; ); acterror=-10000; put "Data and fitted values:"//; loop(S, aux=W0.l+sum(I,W.l(I)*X(I,S)); if(ord(J) le 3, f1=arctan(aux); else x1=ymin-(ymax-ymin)*0.1; x2=ymax+(ymax-ymin)*0.1; f1=sum(R,alfa.l(R)*abs(x1)**(powers(R)))-aux; f2=sum(R,alfa.l(R)*abs(x2)**(powers(R)))-aux; if(f1*f2>0.0, put "ERROR IN BISECTION "," S=",S.tl:3," aux=", aux:12:3," f1=",f1:12:3," f2=",f2:12:3/; else while(abs(x1-x2)>maxerror, x3=(x1+x2)*0.5; f3=sum(R,alfa.l(R)*x3**(powers(R)))-aux; if(f3*f1>0.0, x1=x3;f1=f3; else x2=x3;f2=f3; ); ); ); f1=((x1+x2)*0.5); ); loop(I,put X(I,S):12:3," & ";); aux=(f1-Y(S)); if(abs(aux)>acterror,acterror=abs(aux)); put Y(S):12:3," & ",aux:12:3"\\"/; ); put "Maximum error=",acterror:12:9/; ); ******************************************************************** ******************************************************************** $title Mesh SETS I number of elements/1*242/ J number of nodes per element/1*3/ K number of nodes/1*144/ N number of nodes per row/1*12/ D space dimension/1*2/ XFIXED(K) nodes with fixed X YFIXED(K) nodes with fixed Y; ALIAS(K,K1,K2); \end{verbatim} }\label{dynamicex1}{\footnotesize \begin{verbatim} PARAMETER t number of squares per dimension m number of elements per column xmin minimum value of coordinate x xmax maximum value of ccordinate x ymin minimum value of coordinate y ymax maximum value of ccordinate y COORD(K,D) coordinates of the initial mesh nodes; t=card(N); xmin=-2; xmax=2; ymin=-2; ymax=2; m=2*t-2; XFIXED(K)=no; loop(N, XFIXED(K)$(ord(K) eq ord(N))=yes; XFIXED(K)$(ord(K) eq ord(N)+t*t-t)=yes; YFIXED(K)$(ord(K) eq t*ord(N))=yes; YFIXED(K)$(ord(K) eq (ord(N)-1)*t+1)=yes; ); COORD(K,'1')=xmin+floor((ord(K)-1)/t)*(xmax-xmin)/(t-1); COORD(K,'2')=ymin+mod(ord(K)-1,t)*(ymax-ymin)/(t-1); PARAMETER EL(I,J); loop(I, if(mod(ord(I),2) eq 0, EL(I,'1')=(floor((ord(I)-1)/m))*t+floor(mod((ord(I)-1),m)/2+1); EL(I,'2')=(floor((ord(I)-1)/m))*t+floor(mod((ord(I)-1),m)/2+1)+1; EL(I,'3')=(floor((ord(I)-1)/m))*t+floor(mod((ord(I)-1),m)/2+1)+t+1; else EL(I,'1')=(floor((ord(I)-1)/m))*t+floor(mod((ord(I)-1),m)/2+1); EL(I,'2')=(floor((ord(I)-1)/m))*t+floor(mod((ord(I)-1),m)/2+1)+t; EL(I,'3')=(floor((ord(I)-1)/m))*t+floor(mod((ord(I)-1),m)/2+1)+t+1; ); ); VARIABLES z1 function to be optimized X(K) coordinate of node K Y(K) coordinate of node K Z(K) coordinate of node K area(I) area of element I mean mean area of elements; X.l(K)=COORD(K,'1'); Y.l(K)=COORD(K,'2'); X.fx(XFIXED)=COORD(XFIXED,'1'); Y.fx(YFIXED)=COORD(YFIXED,'2'); EQUATIONS Q objective function to be optimized Carea(I) Cf(K) points are in surface Cmean; Q..z1=e=sum(I,sqr(area(I)-mean))/card(I); Carea(I)..area(I)=e=sum((K,K1,K2)$((EL(I,'1') =ord(K)) and (EL(I,'2')=ord(K1)) and (EL(I,'3')=ord(K2))), sqr((Y(K1)-Y(K))*(Z(K2)-Z(K))-(Y(K2)-Y(K))*(Z(K1)-Z(K)))+ sqr((Z(K1)-Z(K))*(X(K2)-X(K))-(Z(K2)-Z(K))*(X(K1)-X(K)))+ sqr((X(K1)-X(K))*(Y(K2)-Y(K))-(X(K2)-X(K))*(Y(K1)-Y(K)))); Cf(K)..Z(K)=e=(X(K)*Y(K)*(sqr(X(K))-sqr(Y(K))))/(sqr(X(K))+sqr(Y(K))); Cmean..mean=e=sum(I,area(I))/card(I); MODEL mallas/ALL/; SOLVE mallas USING nlp MINIMIZING z1; file out/mallas3.out/; put out; if((card(I) ne (2*(t-1)*(t-1))), put "Error, card(I) must be equal to ",(2*(t-1)*(t-1)):8:0/; else if((card(K) ne t*t), put "Error, card(K) must be equal to ",(t*t):8:0/; else put "z1=",z1.l:12:8," mean=",mean.l:12:8, " cpu=",mallas.resusd:9:2, " modelstat=",mallas.modelstat:3:0," solvestat=",mallas.solvestat:3:0/; loop(K, put "X(",K.tl:3,")=",COORD(K,'1'):12:8," Y(",K.tl:3,")=",COORD(K,'2'):12:8/; ); loop(I, put "I=",i.tl:3," Nodes=",EL(I,'1'):5:0," ",EL(I,'2'):5:0," ",EL(I,'3'):5:0/; ); loop(K, put "K=",K.tl:3," X=",X.l(K):12:6," Y=",Y.l(K):12:6," Z=",Z.l(K):12:6/; ); loop(I, put "I=",I.tl:3," area=",area.l(I):12:6/; ); put "COORDINATES"/; put "{"; loop(K, if(ord(K)