/* animation based upon Java 1.1.6 AnimRotator.java 13 april 08 */ /* This applet is intended to be as far as possible a straight word for word recreation of Exidy Sorcerer Basic economic simulation model PHT42g. S/rtns numbered as PHT42G */ /* P[g][0][0] = 0 means tool g unavailable. P[g][0][1] = 'basic' or untooled amount of tool-0 (labour) used in making 1 unit of tool/good g. P[g][t][1] = amount or fraction of tool t used in making one unit of good g. P[g][t][2] = amount of labour time (tool-0) saved by using tool t in making one unit of good g. If amount_used[tool].price[tool] < labour_time_saved.price[labour] a tool is worth using. P[g][t][3] = P[g][t][1] with tools not worth using omitted. */ /* T[M][G][0] N manufactured input register T[M][G][1] N purchased input register T[M][G][2] N use output register T[M][G][3] N sale output register T[M][G][4] N total profit T[M][G][5] N profitability T[M][G][6] N manufactured input cost T[M][G][7] N purchased input cost T[M][G][8] N use output price T[M][G][9] N sale output price T[M][G][10] N use thruput - daily through T[M][G][2] T[M][G][11] N sale thruput - daily through T[M][G][3] T[M][G][12] N production target (damped) T[M][G][13] N purchase target (damped) T[M][G][14] N total use thruput T[M][G][15] N total sale thruput T[M][G][16] N day's damped production target T[M][G][17] N day's damped purchase target T[M][G][18] N price movement factor T[M][G][19] N T[M][G][20] N */ import java.awt.Graphics; import java.awt.image.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.lang.*; public class Pht42g extends java.applet.Applet implements Runnable { private Thread testThread = null; int count; Dimension appletSize; Image offImage; Graphics offGraphics; private Image img, img2; boolean go = true; boolean updateNotBusy = true; int mouseCount; MemoryImageSource mis; /* PHT42g variables */ int NM; int QM = 4; int QT = 5; int M, G, TX, M1, M2, M3, MZ, DY, N1, t; double AV, CV, XV; double PMF; // price movement factor double MF; double Amt; // some amount double p2; double T[][][] = new double[10][10][25]; double P[][][] = new double[10][10][6]; double W[][] = new double[10][12]; double A[] = new double[10]; double B[] = new double[10]; double C[] = new double[10]; double O[] = new double[105]; double L[] = new double[10]; double P1[][] = { { 1, 0.45, 0, 0.1, 0, 0 }, { 1, 0, 0.1, 0.1, 0.05, 0.05 }, { 2, 0, 0.02, 0.3, 0.04, 0.05 }, { 2.5, 0, 0.1, 0.3, 0.02, 0.18 }, { 1, 0, 0.3, 0.1, 0.02, 0.03 }, { 2, 0, 0.14, 0.2, 0.02, 0.1 } }; double P2[][] = { { 0, 0.95, 0, 0.04, 0, 0 }, { 0, 0, 0.2, 0.25, 0.1, 0.05 }, { 0, 0, 0.02, 1.0, 0.05, 0.05 }, { 0, 0, 0.3, 1.5, 0.02, 0.20 }, { 0, 0, 0.1, 0.4, 0.03, 0.02 }, { 0, 0, 0.3, 0.5, 0.02, 0.3 } }; public void init() { count = 0; mouseCount = 0; appletSize = this.getSize(); System.out.println( appletSize.width ); this.enableEvents( AWTEvent.MOUSE_EVENT_MASK ); setBackground(Color.blue); /* PHT42g initializations */ for ( int g=0; g<=QT; g++ ) { P[g][0][0] = 1; }; for ( int g=0; g<=QT; g++ ) { for ( int t=0; t<=QT; t++ ) { P[g][t][1] = P1[g][t]; P[g][t][2] = P2[g][t]; }; }; System.out.println( P[3][4][0] ); DY = 0; /* provisional startup gives them tools, prices, targets */ // for ( int u = 0; u < QT; u++ ) { // L[u] = 1.0; // System.out.print( u ); // } System.out.println(); pr1000(); totalFractionTable(); } public void start() { if (testThread == null) { testThread = new Thread(this, "Test1"); testThread.start(); } } public void processMouseEvent( MouseEvent e) { if ( e.getID() == MouseEvent.MOUSE_ENTERED ) { } else if ( e.getID() == MouseEvent.MOUSE_EXITED ) { } else if ( e.getID() == MouseEvent.MOUSE_RELEASED ) { if ( mouseCount == 0 ) { } else if ( mouseCount == 1 ) { } else { } } else super.processMouseEvent(e); } public void run() { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); Thread myThread = Thread.currentThread(); while (testThread == myThread) { if ( go ) { System.out.println( "Day " + count ); // pr100(); // for ( M = 0; M < QM; M++ ) { // System.out.print( T[M][TX][11]+ " " ); // } // System.out.println(); // for ( M = 0; M < QM; M++ ) { // System.out.print( T[M][1][11]+ " " ); // } // System.out.println(); repaint(); count++; } try { Thread.sleep( 500 ); } catch (InterruptedException e){ } } } public void paint(Graphics g) { update(g); } public void update(Graphics g) { if (go) { if ( img2 != null ) { setBackground(Color.blue); g.drawImage( img2, 0, 0, this ); } } else { g.drawImage( img, 0, 0, this ); } } public void stop() { testThread = null; } /* data input */ void pr1000() { NM = QM + 1; // QM = NM - 1 TX = 2; MF = 1.5; pr5000(); // smooth kickstart } /* smooth kickstart */ void pr5000() { int m, t; double x; System.out.println( "Smooth kickstart" ); pr30000(); PMF = 0.9; for ( m=0; m<=QM; m++ ) { x = 0; for ( t=0; t<=QT; t++ ) { if ( P[t][0][0] > 0 ) { T[m][t][0] = A[t]; if ( t == 0 ) T[m][t][0] = 10; T[m][t][1] = A[t]; x = x + A[t] * L[t]; T[m][t][2] = A[t]; T[m][t][3] = A[t]; T[m][t][4] = A[t] * L[t] * (1-1/MF); T[m][t][6] = L[t] / MF; T[m][TX][6] = 1.5; T[m][t][7] = L[t]; T[m][t][8] = L[t]; T[m][t][9] = L[t]; T[m][t][10] = A[t]; T[m][t][11] = A[t]; T[m][t][16] = A[t]; T[m][t][17] = A[t]; T[m][t][18] = PMF; } } T[m][TX][1] = x; T[m][TX][3] = x * 2.0; x = 0; for ( t=0; t<3; t++ ) { x = x + T[m][TX][t]; } T[m][TX][4] = x; } } /* Analytic prediction */ void pr30000() { int t, g, n, x, u, c; double x1, set, rr; System.out.println( "Analytic prediction" ); pr34000(); System.out.println( "Analytic prediction+" ); // prime A and B arrays for ( t=0; t<=QT; t++ ) { A[t] = P[0][t][3]; B[t] = P[0][t][3]; } System.out.println( "Analytic prediction, arrays primed" ); // expand good>0 terms for ( n=1; n<80; n++ ) { for ( g=1; g<=QT; g++ ) { for ( t=0; t<=QT; t++ ) { C[t] = P[g][t][3] * B[g]; // expansion terms } for ( t=0; t<=QT; t++ ) { B[t] = B[t] + C[t]; // add expansion terms if ( t == g ) { B[t] = C[t]; // replace expanded term } A[t] = A[t] + C[t]; // total usage } x1 = 0; for ( x=1; x 0 ) { for ( m = 0; m <= QM; m++ ) { if ( T[m][g][9] < L[g] ) { L[g] = T[m][g][9]; } } } } } /* work out fraction table */ void pr32500() { int g, t; double c; for ( g=0; g<=QT; g++ ) { if ( P[g][0][0] > 0 ) { // if tool exists c = P[g][0][1]; // labour cost for ( t=1; t<=QT; t++ ) { if ( P[t][0][0] > 0 ) { P[g][t][3] = 0; if ( (P[g][t][1] * L[t]) <= (P[g][t][2] * L[0]) ) { c = c - P[g][t][2]; P[g][t][3] = P[g][t][1]; } } } P[g][0][3] = c; } } } /* simultaneous solution for prices */ void pr33000() { int m, row, col, col1; double x1; // clear W-array for ( row=0; row<=QT+1; row++ ) { for ( col=0; col<=QT+5; col++ ) { W[row][col] = 0; } } // set up matrix for ( row=0; row<=QT; row++ ) { if ( row != TX ) { for ( col=0; col<=QT; col++ ) { if ( col != TX ) { W[row][col] = P[row][col][3] * MF; } } W[row][QT+2] = -P[row][TX][3] * MF; } } // fix the diagonal coefficient for ( row=0; row<=QT; row++ ) { W[row][row] = W[row][row] - 1; } // solve simultaneous equations for ( m=0; m<=QT-1; m++ ) { for ( row=0; row<=QT-1; row++ ) { for ( col=0; col<=QT+1; col++ ) { x1 = W[m][col+1] * W[row+1][m] / W[m][m]; W[row+1][col+1] = W[row+1][col+1] - x1; } } } // backward calculation for ( col=QT; col>=0; col-- ) { for ( col1=col+1; col1<=QT+1; col1++ ) { W[col][QT+2] = W[col][QT+2] - W[col][col1]; } W[col][QT+3] = W[col][QT+2] / W[col][col]; if ( (col == QT ) && (W[col][QT+3] == 0 ) ) W[col][QT+3] = 1; for ( row=0; row<= col-1; row++ ) { W[row][col] = W[row][col] * W[col][QT+3]; } } } /* Iterative calls to sim equ solver */ void pr34000() { int u, c, n; double set, rr; for ( u = 0; u <= QT; u++ ) { System.out.print( u ); L[u] = 1.0; } System.out.println( "Iterative call to sim equ solver" ); QT = QT -1; // Iterative calls to sim equ solver set = 1.0; rr = 1.0; n = 0; while ( (rr == 1.0) && (set == 1.0) ) { System.out.print( " " + n ); pr32500(); // get fraction table pr33000(); // solve simultaneous equations if ( W[QT][QT+3] == 1.0 ) { set = 0.25; } rr = 0.0; for ( c = 0; c <= QT; c++ ) { if ( c == TX ) { W[c][QT+3] = 1.0; } if ( L[c] != W[c][QT+3] ) { rr = 1; } L[c] = W[c][QT+3]; } n++; if ( n > 0 ) { // just one loop limit rr = 0; } } if ( L[QT] == 5 ) { System.out.print( "Non-" ); } System.out.println ("Unique values of p[t]"); for ( u = 0; u <= QT; u++ ) { L[u] = L[u] * set; System.out.print( L[u] ); } System.out.println(); QT = QT + 1; printFractionTable(); } void printFractionTable() { int g, t; for ( t = 0; t <= QT; t++ ) { for ( g = 0; g <= QT; g++ ) { System.out.print( (float)(P[g][t][3]) + " " ); } System.out.println(); } } /* 13 May 81 */ /* I don't understand why useless tool 5 seems to be used */ void totalFractionTable() { int n, g, t; double x1, subtotal; double total[][] = new double[QT+1][3]; total[0][1] = 1.0; // to make 1 day for ( t=1; t<=QT; t++ ) { total[t][1] = P[0][t][1]; // tools required total[t][2] = total[t][1]; System.out.print( (float)P[0][t][1] + " " ); } System.out.println( ); for ( n=0; n<1; n++ ) { for ( g=1; g<=QT; g++ ) { subtotal = total[g][2]; total[g][2] = 0.0; for ( t=1; t<=QT; t++ ) { x1 = P[g][t][1] * subtotal; total[t][1] = total[t][1] + x1; total[t][2] = total[t][2] + x1; } } System.out.print( (float)total[5][1] + " " ); } System.out.println( ); System.out.print( "totals - " ); for ( g=0; g<=QT; g++ ) { System.out.print( (float)total[g][1] + " " ); for ( t=0; t