Post Reply 
Simplex Program
02-28-2016, 05:15 PM (This post was last modified: 02-28-2016 05:16 PM by markelg.)
Post: #1
Simplex Program
Does anyone know how I can get or what I can change to get exact answers from this Simplex program?

Thanks

Code:

PHASEONE();
SPIVOT();
ROUNDING();

EXPORT SIM16()
BEGIN
LOCAL V,C,P,S1,S2,S3,S4,S5;
LOCAL O,I,L,M,T,TAB,A,B;
LOCAL E,K,S,Z,Q,NEG,STP1,STP2;
LOCAL NZR,NZN,J,R,NSE,MIN;
LOCAL LLL,RRR,MCL,MAX,ONEZC;
LOCAL Q1,Q2,Q3,Q4,W,ORG,OOK;
LOCAL ALLN,LA,LB,ILL,ILL2,MTS,FST;
LOCAL MTAB,LST,LMX,SAM,FIX,PACK;
LOCAL II,KK,LATAB,JJ,CON,INF,ILL3;
LOCAL OTAB,TEMP,ILL4,ORGTAB;
INPUT({{V,[0],{55,20,0}},{C,[0],{55,20,1}}},"SIMPLEX",{"NUMBER OF VARIABLES:","NUMBER OF CONSTRINTS:"});
O:=MAKELIST(0,X,1,V);
T:=MAKELIST(O,X,1,C);
E:=MAKELIST(0,X,1,C);
S:=MAKELIST(2,X,1,C);
S1:="{P,{""Max"",""Min""},{1,17,0}}";
S3:="";
S4:="""P"",";
M:=−1;
FOR I FROM 1 TO V DO
IF ((I MOD 3)==1) THEN L:=27;END;
IF ((I MOD 3)==2) THEN L:=27+27;END;
IF ((I MOD 3)==0) THEN L:=27+27*2;END;
IF (I MOD 3)==1 THEN M:=M+1;END; 
S3:=S3+"{O("+I+"),[0],{"+L+",18,"+M+"}},";
S4:=S4+"""+X"+I+""",";
END;
S3:=LEFT(S3,DIM(S3)-1);
S5:="";
M:=M+1;
FOR K FROM 1 TO C DO
FOR I FROM 1 TO V DO
IF ((I MOD 3)==1) THEN L:=6;END;
IF ((I MOD 3)==2) THEN L:=6+24;END;
IF ((I MOD 3)==0) THEN L:=6+24*2;END;
IF ((I MOD 3)==1) THEN M:=M+1;END;
S5:=S5+"{T("+K+","+I+"),[0],{"+L+",17,"+(M)+"}},";
S4:=S4+"""X"+I+""",";
END;
S5:=S5+"{S("+K+"),{""≥"",""≤"",""=""},{72,9,"+(M)+"}},{E("+K+"),[0],{82,17,"+(M)+"}},";
S4:=S4+""""","""",";
END;
S5:=LEFT(S5,DIM(S5)-1);
S4:=LEFT(S4,DIM(S4)-1);
S2:="INPUT({"+S1+","+S3+","+S5+"},""SIMPLEX"",{"+S4+"})";
EXPR(S2);
//////////////////////////////
//PRINT EQUATIONS
PRINT();
S1:="";
IF P==1 THEN S1:="MAXIMIZE: P= ";
ELSE S1:="MINIMIZE: P= ";END;
FOR I FROM 1 TO V DO
IF SIGN(O(I))==−1 THEN S1:=S1+" - ";END;
IF SIGN(O(I))≥0 AND I≠1 THEN S1:=S1+" + ";END;
S1:=S1+ABS(O(I))+"_X"+I;
END;//FOR I
PRINT(S1);
PRINT("SUBJECT TO:");
FOR K FROM 1 TO C DO
S1:="";
FOR I FROM 1 TO V DO
IF SIGN(T(K,I))==−1 THEN S1:=S1+" - ";END;
IF SIGN(T(K,I))≥0 AND I≠1 THEN S1:=S1+" + ";END;
S1:=S1+ABS(T(K,I))+"_X"+I;
END;//FOR I
IF S(K)==1 THEN S1:=S1+" ≥ ";END;
IF S(K)==2 THEN S1:=S1+" ≤ ";END;
IF S(K)==3 THEN S1:=S1+" = ";END;
IF SIGN(E(K))==−1 THEN S1:=S1+"-";END;
S1:=S1+ABS(E(K));
PRINT(S1);
END;//FOR K
PRINT("---------------------");
///////////////////////////////////
//Equal
FIX:=SIZE(S);
FOR I FROM 1 TO FIX DO
IF S(I)==3 THEN
S(I):=2;
C:=C+1;
T(C):=T(I);
E(C):=E(I);
S(C):=1;
END;//IF S(I)
END;//FOR I
///////////////////////////////////
TAB:=append(T,(−1)^P*O);
TAB:=list2mat(TAB);
A:=MAKEMAT(0,1,C+1);
FOR I FROM 1 TO C DO
A:=A*0;
A(1,I):=(−1)^S(I);
ADDCOL(TAB,A(1),V+I);
END;
Z:=MAKEMAT(0,1,C+1);
Z(1,C+1):=1;
ADDCOL(TAB,Z(1),C+V+1);
E:=append(E,0);
B:=list2mat(E,C+1);
ADDCOL(TAB,B(1),C+V+2);
ORG:=TAB;
//RETURN(TAB);
//////////////////////////////////////////////////////////////////////////////
//PHASE ONE
STP1:=0;
PACK:={};
PACK:=PHASEONE(TAB,C,V,STP1);
TAB:=PACK(1);
STP1:=PACK(4);
///////////////////////////////////////////////////////////////////
//SIMPLEX
STP2:=0;
REPEAT
MIN:=1ᴇ12;NEG:=0;TEMP:=ROUNDING(TAB,C,V,6);
IF TEMP(C+1,C+V+1)<0 THEN TAB(C+1):=-1*TAB(C+1);TEMP(C+1):=-1*TEMP(C+1);END;
FOR LA FROM 1 TO C+1 DO
ALLN:=1;
FOR LB FROM 1 TO C+V+2 DO
IF TEMP(LA,LB)>0 THEN ALLN:=0;END;
END;//FOR-LB
IF ALLN THEN TAB(LA):=−1*TAB(LA);TEMP(LA):=−1*TEMP(LA);END;
END;//FOR-LA  
OOK:=2;
FOR I FROM 1 TO V+C DO
IF (TEMP(C+1,I)<0) AND (TEMP(C+1,I)<MIN) THEN 
OOK:=0;
FOR K FROM 1 TO C DO
IF SIGN(TEMP(K,C+V+2))*TEMP(K,I)>0 OR (TEMP(K,I)>0 AND TEMP(K,C+V+2)==0) THEN
OOK:=1;
END;//IF2
END;//FOR-K
IF OOK==1 THEN
MIN:=TEMP(C+1,I);J:=I;NEG:=1;
END;//IF3
END; 
END;//FOR-I
IF NEG==1 THEN 
MIN:=1ᴇ12;R:=0;
FOR K FROM 1 TO C DO
IF SIGN(TEMP(K,C+V+2))*TEMP(K,J)>0 OR (TEMP(K,J)>0 AND TEMP(K,C+V+2)==0) THEN
IF RANDINT(1,2)==1 THEN
Q1:=(TEMP(K,C+V+2)/TEMP(K,J))<MIN;
ELSE
Q1:=(TEMP(K,C+V+2)/TEMP(K,J))<=MIN;
END;
Q2:=(TEMP(K,C+V+2)/TEMP(K,J))≥0;
IF  Q1 AND Q2 THEN
MIN:=TEMP(K,C+V+2)/TEMP(K,J);
R:=K;
END;
END;
END;
//
TAB:=SPIVOT(TAB,R,J);
//////////////////////////
//TAB:=ROUNDING(TAB,C,V,9);
//FOR II FROM 1 TO C+1 DO
//FOR KK FROM 1 TO C+V+2 DO
//TAB(II,KK):=ROUND(TAB(II,KK),9);
//END;//FOR KK
//END;//FOR II
//////////////////////////
PRINT("SIMPLEX ROW="+R+" COL="+J);
IF ROUND(TAB(C+1,C+V+1),6)<0 THEN TAB(C+1):=-1*TAB(C+1);END;
//FOR W FROM 1 TO C+1 DO
//IF lgcd(TAB(W))>0 THEN TAB(W):=TAB(W)/lgcd(TAB(W));END;
//END;//FOR W
//////////
PACK:=PHASEONE(TAB,C,V,STP1);
TAB:=PACK(1);
STP1:=PACK(4);
//////////
//RETURN(TAB);
END;
//PRINT("OOK="+OOK);
STP2:=STP2+1;
UNTIL NEG==0 OR STP2>=100;
//RETURN(TAB);
////////////////////////////////////////////////
//ROUNDING
ORGTAB:=TAB;
TAB:=ROUNDING(TAB,C,V,6);
//FOR II FROM 1 TO C+1 DO
//FOR KK FROM 1 TO C+V+2 DO
//TAB(II,KK):=ROUND(TAB(II,KK),6);
//END;//FOR KK
//END;//FOR II

//CHECK INVALID SOLUTION
/////////////////////////////////////////////////
ILL2:=0;
FOR I FROM 1 TO C+V DO
NZN:=0;NZR:=0;
FOR K FROM 1 TO C+1 DO
IF TAB(K,I)≠0 THEN NZN:=NZN+1;NZR:=K;END;
END;//FOR-K
IF NZN≠0 THEN
IF (NZN==1) AND (SIGN(TAB(NZR,C+V+2))*SIGN(TAB(NZR,I))<0) THEN 
ILL2:=1;
END;//IF-(NZN==1)
END;//IF-NZN≠0
END;//FOR-I
////////////////////////////////////////////////
//FIND VALID SOLUTION
PRINT("---------------------");
JJ:=2;LATAB:={};ILL4:=0;
LATAB(1):=ORG;
LATAB(2):=TAB;
MTAB:=TAB;MTS:={};FST:=0;LST:={};LMX:={};
ILL3:=0;

REPEAT
FST:=FST+1;
S1:="";CON:={};INF:=0;
FOR I FROM 1 TO V+C DO
NZN:=0;NZR:=0;
FOR K FROM 1 TO C+1 DO
IF MTAB(K,I)≠0 THEN NZN:=NZN+1;NZR:=K;END;
END;
IF NZN==1 THEN 
IF I≤V THEN
IF contains(CON,NZR)==0 THEN
CON:=append(CON,NZR);
ELSE
INF:=1;ILL3:=1;
END;//IF CONTAINS
END;//IF I≤V
MTAB(NZR):=ROUND(MTAB(NZR)/MTAB(NZR,I),4);
IF I<=V AND INF==0 THEN S1:=S1+"X"+I+"="+MTAB(NZR,C+V+2)+" , ";END;
IF I≤V AND INF==1 THEN S1:=S1+"X"+I+"=0 , ";END; 
ELSE
IF I<=V THEN S1:=S1+"X"+I+"=0 , ";END;
IF MTAB(C+1,I)==0 AND FST==1 THEN MTS:=append(MTS,I);END;
END;
END;
IF MTAB(C+1,C+V+1)≠0 THEN 
MTAB(C+1):=ROUND(MTAB(C+1)/MTAB(C+1,C+V+1),4);
S1:=S1+"P="+((-1)^(P+1)*MTAB(C+1,C+V+2));
ELSE
S1:=S1+"P=NA"
END;

SAM:=0;
IF FST==1 THEN
PRINT(S1);
PRINT("---------------------");
ELSE
FOR I FROM 1 TO FST-1 DO
IF S1==LST(I) THEN SAM:=1;END;
END;//FOR I
IF SAM==0 THEN 
PRINT(S1);
PRINT("---------------------");
JJ:=JJ+1;
LATAB(JJ):=OTAB;
ILL4:=1;
END;//IF SAM
END;//IF FST

IF SIZE(MTS)>0 AND FST==1 THEN
FOR I FROM 1 TO SIZE(MTS) DO

MIN:=1ᴇ12;R:=0;
FOR K FROM 1 TO C DO
IF SIGN(TAB(K,C+V+2))*TAB(K,MTS(I))>0 OR (TAB(K,MTS(I))>0 AND TAB(K,C+V+2)==0) THEN
Q1:=(TAB(K,C+V+2)/TAB(K,MTS(I)))<MIN;
Q2:=(TAB(K,C+V+2)/TAB(K,MTS(I)))≥0;
IF  Q1 AND Q2 THEN
MIN:=TAB(K,C+V+2)/TAB(K,MTS(I));
R:=K;
END;
END;
END;

IF R==0 THEN 
LMX(I):=TAB;
ELSE
LMX(I):=ROUNDING(SPIVOT(ORGTAB,R,MTS(I)),C,V,6);
END;//IF R

END;//FOR I
END;//IF-SIZE

IF SIZE(MTS)>0 AND FST≤SIZE(MTS) THEN
MTAB:=LMX(FST);
OTAB:=MTAB;
LST(FST):=S1;
END;//IF SIZE

UNTIL FST==(SIZE(MTS)+1);


//PRINT();
//PRINT({V,C,P});
//PRINT(O);
//PRINT(T);
//PRINT(S);
//PRINT(B);
//PRINT(TAB);
//PRINT(S1);
IF OOK==0 OR STP1==100 OR STP2==100 OR (ILL AND (STP2==0) AND 0) OR (ILL2 AND 1) THEN 
PRINT("*may not have optimal solution*");
END;//IF-OOK
//PRINT({"OOK=",OOK,"STP1=",STP1,"STP2=",STP2,"ILL=",ILL,"ILL2=",ILL2,"ILL3=",ILL3});
IF ILL3 THEN PRINT("*Infinitely many solutions*");END;
IF OOK==0 AND ILL2==0 THEN PRINT("*Unbounded*");END;
IF ILL2 THEN PRINT("*No feasible solution*");END;
IF ILL4 THEN PRINT("*Multiple optimal solutions*");END;
//IF SIZE(MTS)>0 THEN 
//PRINT("*may has more than one solution*");
//END;//IF-SIZE
//RETURN({ORG,TAB});
PRINT("-END-");
RETURN(LATAB);
END;






PHASEONE(TAB,C,V,STP1)
BEGIN
//PHASE ONE
LOCAL LA,LB,ALLN,ONEZC;
LOCAL ILL,LLL,NSE,NZN,NZR,K,I;
LOCAL RRR,MCL,W,MAX;
LOCAL II,KK,TEMP;

ONEZC:=0;
REPEAT
TEMP:=ROUNDING(TAB,C,V,6);
FOR LA FROM 1 TO C+1 DO
ALLN:=1;ILL:=0;
FOR LB FROM 1 TO C+V+2 DO
IF TEMP(LA,LB)>0 THEN ALLN:=0;END;
END;//FOR-LB
IF ALLN THEN TAB(LA):=−1*TAB(LA);TEMP(LA):=−1*TEMP(LA);END;
END;//FOR-LA
NSE:=0;LLL:=0;
FOR I FROM 1 TO C+V DO
NZN:=0;NZR:=0;
FOR K FROM 1 TO C+1 DO
IF TEMP(K,I)≠0 THEN NZN:=NZN+1;NZR:=K;END;
END;//FOR-K
IF NZN≠0 THEN
IF (NZN==1) AND (SIGN(TEMP(NZR,C+V+2))*SIGN(TEMP(NZR,I))<0) AND (ONEZC==0) THEN 

ALLN:=1;
FOR LB FROM 1 TO C+V DO
IF SIGN(TEMP(NZR,C+V+2))*SIGN(TEMP(NZR,LB))>0 THEN ALLN:=0;END;
END;//FOR-LB

IF ALLN==0 THEN
NSE:=1;RRR:=NZR;LLL:=I;
ELSE
ILL:=1;
END;//IF-ALLN

END;//IF-(NZN==1)
END;//IF-NZN≠0
//IF (NZN==1) AND (TAB(NZR,C+V+2)==0) AND (ONEZC==0)THEN NSE:=1;RRR:=NZR;LLL:=I;ONEZC:=1;END;
END;//FOR-I

IF NSE==1 THEN
MAX:=0;MCL:=0;
FOR I FROM 1 TO C+V DO
IF SIGN(TEMP(RRR,C+V+2))*TEMP(RRR,I)>MAX AND I≠LLL THEN MCL:=I;MAX:=SIGN(TEMP(RRR,C+V+2))*TEMP(RRR,I);END;
END;
//TAB(RRR):=TAB(RRR)/TAB(RRR,MCL);
TAB:=SPIVOT(TAB,RRR,MCL);
////////////////////////
//TAB:=ROUNDING(TAB,C,V,9);
//FOR II FROM 1 TO C+1 DO
//FOR KK FROM 1 TO C+V+2 DO
//TAB(II,KK):=ROUND(TAB(II,KK),9);
//END;//FOR KK
//END;//FOR II
///////////////////////
PRINT("PHASE ONE:ROW="+RRR+" COL="+MCL);
//FOR W FROM 1 TO C+1 DO
//IF lgcd(TAB(W))>0 THEN TAB(W):=TAB(W)/lgcd(TAB(W));END;
//END;//FOR W
//IF WAIT(−1)==30 THEN RETURN(TAB);END;

END;
STP1:=STP1+1;
UNTIL NSE==0 OR STP1>=100;
RETURN({TAB,C,V,STP1});
END;

SPIVOT(M,RO,CO)
BEGIN
LOCAL T,K,SI;
T:=M;
SI:=SIZE(M);
T(RO):=M(RO)/M(RO,CO);
FOR K FROM 1 to SI(1) DO
IF K≠RO THEN
T(K):=M(K)-M(K,CO)*T(RO);
END;//IF K≠RO
END;//FOR K
RETURN(T);
END;

ROUNDING(M,C,V,D)
BEGIN
LOCAL II,KK;
FOR II FROM 1 TO C+1 DO
FOR KK FROM 1 TO C+V+2 DO
M(II,KK):=ROUND(M(II,KK),D);
END;//FOR KK
END;//FOR II
RETURN(M);
END;
Find all posts by this user
Quote this message in a reply
02-28-2016, 06:18 PM
Post: #2
RE: Simplex Program
(02-28-2016 05:15 PM)markelg Wrote:  Does anyone know how I can get or what I can change to get exact answers from this Simplex program?

Thanks

Three cheers for even trying to implement a complex LP algorithm on a pocket calculator--I too attempted this task many years ago on an HP41c, with no success at all.

It would be helpful to have your sample input data as well as the current output you got. Also, what do you mean by "exact answers"? If my memory serves, "integer" programming might be necessary if you want, for example, the optimal number of machines needed to satisfy the constraint in a production model. (i.e. you can't have 2.57 machines)
Visit this user's website Find all posts by this user
Quote this message in a reply
02-28-2016, 06:27 PM
Post: #3
RE: Simplex Program
(02-28-2016 06:18 PM)dbbotkin Wrote:  Three cheers for even trying to implement a complex LP algorithm on a pocket calculator--I too attempted this task many years ago on an HP41c, with no success at all.

It would be helpful to have your sample input data as well as the current output you got. Also, what do you mean by "exact answers"? If my memory serves, "integer" programming might be necessary if you want, for example, the optimal number of machines needed to satisfy the constraint in a production model. (i.e. you can't have 2.57 machines)

For example, if I input 5 variables x 2 constraints, then input the values
Quote:Max: 0 36 24 0 6
then
6 2 1 0 0 = 11
0 28 -1 6 0 = 31
it will output my answer as for x5=5.1667.
This is close to correct, but I need it to be 5.16666666667 so that I can convert that to 31/6 (the correct answer option on a piece of homework I'm working on). When I convert 5.1667 to a fraction it's 51667/1000.

There may be another way around this, I'm new to the prime and programming so sorry if it's not making much sense or if I'm overlooking a simple setting to fix it.
Find all posts by this user
Quote this message in a reply
02-28-2016, 07:24 PM (This post was last modified: 02-28-2016 07:36 PM by DrD.)
Post: #4
RE: Simplex Program
Would the home variable HDigits be useful for you?

HDigits:=11; // Example.

Another way that may be helpful: You can use the [a b/c] key to toggle the fraction result:

5.16666666667
31/6
5+1/6

-Dale-
Find all posts by this user
Quote this message in a reply
02-28-2016, 08:23 PM
Post: #5
RE: Simplex Program
(02-28-2016 07:24 PM)DrD Wrote:  Would the home variable HDigits be useful for you?

HDigits:=11; // Example.

Another way that may be helpful: You can use the [a b/c] key to toggle the fraction result:

5.16666666667
31/6
5+1/6

-Dale-
I'm reading what HDigits is used for, but I'm not sure how it would tie into this.
When [a b/c] is pressed in the program it exits out, but even then it would still just be converting 5.1667. 31/6 would be an unknown if I didn't have the answer key.

I'm thinking it has to do something with the rounding in the code itself but I'm not sure how that works since I didn't write the program. It seems as if all answers given are rounded to the ten thousandth.
Find all posts by this user
Quote this message in a reply
02-28-2016, 11:29 PM
Post: #6
RE: Simplex Program
(02-28-2016 06:27 PM)markelg Wrote:  
(02-28-2016 06:18 PM)dbbotkin Wrote:  Three cheers for even trying to implement a complex LP algorithm on a pocket calculator--I too attempted this task many years ago on an HP41c, with no success at all.

It would be helpful to have your sample input data as well as the current output you got. Also, what do you mean by "exact answers"? If my memory serves, "integer" programming might be necessary if you want, for example, the optimal number of machines needed to satisfy the constraint in a production model. (i.e. you can't have 2.57 machines)

For example, if I input 5 variables x 2 constraints, then input the values
Quote:Max: 0 36 24 0 6
then
6 2 1 0 0 = 11
0 28 -1 6 0 = 31
it will output my answer as for x5=5.1667.
This is close to correct, but I need it to be 5.16666666667 so that I can convert that to 31/6 (the correct answer option on a piece of homework I'm working on). When I convert 5.1667 to a fraction it's 51667/1000.

There may be another way around this, I'm new to the prime and programming so sorry if it's not making much sense or if I'm overlooking a simple setting to fix it.
Ah yes, a 'homework assignment' where exact answers matter. In the real world, an LP problem, or other algorithm for that matter, is bound not only by the constraints applied to the variables but also by the precision and accuracy of the input data. Often these data are either forecasts or averages with only a few significant digits, neither of which would support an answer out to 12 places. Besides, a repeating decimal like .1666...7 is best regarded as just plain one-sixth and the same goes for the other repeating-series answers.

If it is any comfort, I had the same frustration back in grad-school cranking out Simplex solutions by doing the matrix math by hand. A fraction like '1/3' says all that can be said about the data at that point in the computation and using decimals makes it harder.
Visit this user's website Find all posts by this user
Quote this message in a reply
02-28-2016, 11:45 PM (This post was last modified: 02-28-2016 11:47 PM by DrD.)
Post: #7
RE: Simplex Program
I guess I didn't quite understand your questions. I was thinking that your exercise left 5.1667 in the display. From that you wanted to get it in the form of an improper fraction. You asked how to get the display output to indicate 5.16666666667, which HDigits would do, if not already there by default. Then you wanted to convert that number to 31/6, which could be done using the [a b/c] key.

Did you want the program to just handle that during run time, instead?

-Dale-
Find all posts by this user
Quote this message in a reply
02-29-2016, 12:54 AM
Post: #8
RE: Simplex Program
Have you considered writing a CAS program instead?

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-29-2016, 05:14 AM (This post was last modified: 02-29-2016 05:18 AM by markelg.)
Post: #9
RE: Simplex Program
(02-28-2016 11:45 PM)DrD Wrote:  I guess I didn't quite understand your questions. I was thinking that your exercise left 5.1667 in the display. From that you wanted to get it in the form of an improper fraction. You asked how to get the display output to indicate 5.16666666667, which HDigits would do, if not already there by default. Then you wanted to convert that number to 31/6, which could be done using the [a b/c] key.

Did you want the program to just handle that during run time, instead?

-Dale-

Correct, sorry for the misunderstanding. Is that possible?

(02-29-2016 12:54 AM)Han Wrote:  Have you considered writing a CAS program instead?

I've never written a program, I found this one and I'm simply trying to build on it/make it better for what I'm doing. I can see how learning to write programs would be useful, may try it out here and there when I have the time.
Find all posts by this user
Quote this message in a reply
02-29-2016, 10:23 AM
Post: #10
RE: Simplex Program
(02-29-2016 05:14 AM)markelg Wrote:  
(02-28-2016 11:45 PM)DrD Wrote:  I guess I didn't quite understand your questions. I was thinking that your exercise left 5.1667 in the display. From that you wanted to get it in the form of an improper fraction. You asked how to get the display output to indicate 5.16666666667, which HDigits would do, if not already there by default. Then you wanted to convert that number to 31/6, which could be done using the [a b/c] key.

Did you want the program to just handle that during run time, instead?

-Dale-

Correct, sorry for the misunderstanding. Is that possible?

I've never written a program, I found this one and I'm simply trying to build on it/make it better for what I'm doing. I can see how learning to write programs would be useful, may try it out here and there when I have the time.

The short answer is "yes." ...
Find all posts by this user
Quote this message in a reply
02-29-2016, 05:52 PM (This post was last modified: 02-29-2016 09:09 PM by markelg.)
Post: #11
RE: Simplex Program
(02-29-2016 10:23 AM)DrD Wrote:  
(02-29-2016 05:14 AM)markelg Wrote:  Correct, sorry for the misunderstanding. Is that possible?

I've never written a program, I found this one and I'm simply trying to build on it/make it better for what I'm doing. I can see how learning to write programs would be useful, may try it out here and there when I have the time.

The short answer is "yes." ...

I might have found the solution, using the hp ppl reference the syntax for rounding is
Quote:ROUND(value, [places])
so somewhere in the program there's a value of 4 with the round command. I'll find/switch them and post result.

Update: I was correct, just had to change the syntax!
Find all posts by this user
Quote this message in a reply
03-01-2016, 05:48 PM
Post: #12
RE: Simplex Program
(02-28-2016 06:18 PM)dbbotkin Wrote:  Three cheers for even trying to implement a complex LP algorithm on a pocket calculator--I too attempted this task many years ago on an HP41c, with no success at all.

Well, it's not so hard to do it - within the last 30 years I've written such LP/Simplex programs for the Sharp-PC1500, the HP-48SX and the TI-92+.
I've also made several versions for the PC, which are of course much more powerful - the last version (LinOpt v6.0) can be downloaded from my website:
http://fhub.jimdo.com/

(02-28-2016 06:27 PM)markelg Wrote:  For example, if I input 5 variables x 2 constraints, then input the values
Quote:Max: 0 36 24 0 6
then
6 2 1 0 0 = 11
0 28 -1 6 0 = 31
it will output my answer as for x5=5.1667.

These conditions can't lead to a solution, there must be any error in your numbers (e.g. x5 doesn't appear in any of the 2 constraints, so how could its solution be 5.1667?

I've tried your problem with my own program (with the result 'infinite solution') and also with an other program on the internet (with the same result).

Franz
Visit this user's website Find all posts by this user
Quote this message in a reply
03-01-2016, 06:30 PM
Post: #13
RE: Simplex Program
(03-01-2016 05:48 PM)fhub Wrote:  
(02-28-2016 06:18 PM)dbbotkin Wrote:  Three cheers for even trying to implement a complex LP algorithm on a pocket calculator--I too attempted this task many years ago on an HP41c, with no success at all.

Well, it's not so hard to do it - within the last 30 years I've written such LP/Simplex programs for the Sharp-PC1500, the HP-48SX and the TI-92+.
I've also made several versions for the PC, which are of course much more powerful - the last version (LinOpt v6.0) can be downloaded from my website:
http://fhub.jimdo.com/

(02-28-2016 06:27 PM)markelg Wrote:  For example, if I input 5 variables x 2 constraints, then input the values
it will output my answer as for x5=5.1667.

These conditions can't lead to a solution, there must be any error in your numbers (e.g. x5 doesn't appear in any of the 2 constraints, so how could its solution be 5.1667?

I've tried your problem with my own program (with the result 'infinite solution') and also with an other program on the internet (with the same result).

Franz

Impressive contribution Franz! You wouldn't happen to have done any work with 'Non-Negative Least Squares' (NNLS) that could run on the Prime? I developed an algorithm back in the '90s that I would like to implement on the Prime. Pretty small matrices: 4x16 for the independent and 1x16 for the dependent with 4 betas ('weights' =>0 ) and 1 alpha output. It was done in Excel as a DLL, but MSFT doesn't run it anymore.

Thanks,
Donal
Visit this user's website Find all posts by this user
Quote this message in a reply
03-01-2016, 06:39 PM
Post: #14
RE: Simplex Program
(03-01-2016 06:30 PM)dbbotkin Wrote:  You wouldn't happen to have done any work with 'Non-Negative Least Squares' (NNLS) that could run on the Prime?

No, sorry - I've written quite a lot of math programs (especially for the above mentioned calcs), but not for this problem.

And I've not yet programmed anything for the HP-Prime, I don't want to learn one more language, and IMO the Prime's language and handling is rather complicated - I still like the TI-92+/Voyage 200 much more, and they are enough powerful for my purposes.

Franz
Visit this user's website Find all posts by this user
Quote this message in a reply
03-01-2016, 11:23 PM (This post was last modified: 03-01-2016 11:29 PM by Gerson W. Barbosa.)
Post: #15
RE: Simplex Program
(03-01-2016 05:48 PM)fhub Wrote:  
(02-28-2016 06:18 PM)dbbotkin Wrote:  Three cheers for even trying to implement a complex LP algorithm on a pocket calculator--I too attempted this task many years ago on an HP41c, with no success at all.

Well, it's not so hard to do it - within the last 30 years I've written such LP/Simplex programs for the Sharp-PC1500, the HP-48SX and the TI-92+.
I've also made several versions for the PC, which are of course much more powerful - the last version (LinOpt v6.0) can be downloaded from my website:
http://fhub.jimdo.com/

Back in '85 or '86 I wrote such a program in MSX BASIC. The 125 short BASIC lines should be easy to port to the HP-71B. It served my purpose then, but it needs improvement. For whatever reason it handles only < and >. Thus, the two constraints in the second example here become four:

[Image: Simplex_zpsbvt0ao4y.png]

Those were the days :-)
Find all posts by this user
Quote this message in a reply
03-02-2016, 11:47 PM (This post was last modified: 03-02-2016 11:58 PM by informach.)
Post: #16
RE: Simplex Program
Hi!, all:
In the Web, have, one program, for SOLVEX, with solution (but, in Portuguese Language), from ... HP Prime - solução de Simplex - Youtube

The program write, in this Forum, have error, in the MIN.
1) Where see MIN:=1(little rectangle)12 ..., replace, in each case, by MIN:=1E12
2) The result MAXIMIZE, can be, 'Z' or 'P'.
and configure, CAS Setting ... Number Format ... Standard

Kind Regards.
informach
Find all posts by this user
Quote this message in a reply
10-08-2016, 05:00 AM (This post was last modified: 10-08-2016 05:09 AM by cclinus.)
Post: #17
RE: Simplex Program
Hi,

Simplex program was updated to V17. It support CAS mode calculation.
It provides exact value answer (no decimals, leave answer in terms of fractions).

http://www.hpmuseum.org/forum/thread-5281.html
Find all posts by this user
Quote this message in a reply
11-11-2016, 02:53 PM (This post was last modified: 11-11-2016 02:54 PM by cclinus.)
Post: #18
RE: Simplex Program
Hi,

Simplex program is updated to v18, add integer solution and fixed some bugs.

Download link:
http://www.hpmuseum.org/forum/thread-5281.html

Regards,
Find all posts by this user
Quote this message in a reply
11-19-2016, 10:59 AM
Post: #19
RE: Simplex Program
Hi,

Simplex program is updated to V19.
Here are the new features:
1) Mixed integer, continuous and binary solution.
2) Target Z value
3) Mixed branch and cut method for integer solution.
4) Allow Re-edit and save equation data.
5) fix a bug

Regards,

Download Link: http://www.hpmuseum.org/forum/thread-5281.html
Find all posts by this user
Quote this message in a reply
11-26-2016, 07:57 AM (This post was last modified: 11-26-2016 07:59 AM by cclinus.)
Post: #20
RE: Simplex Program
Hi,

Minor update to v19.8.
fix a bug , a not unbounded solution misidentify as unbounded.
Hope it will not cause some new bugs!

Thanks!
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 6 Guest(s)