Exemple #1
0
        private void DRAWTEMP(frmCONOP frm, Graphics g)
        {
            COMMOD COMMOD9 = COMMOD.Singleton();
            string cnt;
            string cool;

            frm.SetColor(15);

            cool = string.Format("{0:0.000000000}", COMMOD9.T);
            cnt = string.Format("{0}", COMMOD9.NTRIES);
            cool = "temp: " + cool.Trim() + "  [null: " + cnt.Trim() + "]";
            cnt = string.Format("{0:0.00000}", COMMOD9.Rx);
            cool = cool.Trim() + "  {ratio: " + cnt.Trim() + "}";
            g.DrawString(cool.Trim(), frm.MSG_FONT_S, frm.DW_Brush, (int)(COMMOD9.maxx / 1.5), (int)(COMMOD9.maxy - 12));
        }
Exemple #2
0
        //---------------------------------------------------------------
        //Subroutine to draw a range chart that illustrates the sequence
        //of observed events in one feasible solution
        //
        //May be "animated" using editcht which alters the range chart to
        //reflect sequence changes made by GONABR.FOR
        //
        //Programmer:        Pete Sadler
        //Last Modified:     January 11 1997
        //---------------------------------------------------------------
        private void DRAWCHT(frmCONOP frm, Graphics g, int trj, int[] HPERM)
        {
            COMMOD COMMOD9 = COMMOD.Singleton();

            int I, typsc;
            int dinc, horscl, font, topfont, dum1, dum2;
            double xreal, yreal;
            //CPMS--WINDOWS Font Management
            int numfonts, index;
            int horiz, vert;
            int scl, top, btm, lft, rit;

            //C----------------------------------------------------------------------
            //CPMS       limits of screen resolution:   maxx  maxy
            //CPMS       margins outside graph box:   top  btm  lft  rit
            //C----------------------------------------------------------------------
            string ltr;

            string xtitle = "";
            string ytitle = "";
            string etitl = "";

            //CPMS----------------------------------------------
            //CPMS  TRJ.LT.2   redraw whole graph
            //CPMS  TRJ.EQ.2   refresh range lines
            //CPMS  TRJ.EQ.3   skeleton graph for event plots
            //CPMS----------------------------------------------
            scl = 0;
            top = 0;
            btm = 50;
            lft = 100;
            rit = 0;
            //CPMS-----------------------------------------------
            horiz = 0;
            vert = -90;//900 in Fortran

            I = 1 - 1;//<=HXD
            Brush brush = frm.MSG_BRUSH_WHITE;
            Pen pen = new Pen(brush);

            Label100:

            //CPMS-----------------------------------------
            if (trj != 2)
            {
                //pause to allow viewing of previous graph
                //clear the screen
                g.Clear(frm.BackColor);

                //draw the axis with current font
                XSCALE(frm, g, COMMOD9.NEVNT, COMMOD9.maxx, COMMOD9.maxy, lft, rit, btm);

            }

            //CPMS---------------------------------------------------------------------
            if (trj != 3)
            {
                //CPMS    Draw full range lines for paired events only
                //C	  if number of available lines is less than the number of taxa+others
                //C  then the following needs to be rewritten so that
                //C  1.  it allots one line to each event
                //C  2.  it stops drawing event ranges after the bottom line on the screen

                for (scl = 0; scl < COMMOD9.NEVNT; scl++)
                {
                    if ((COMMOD9.IROWS[HPERM[scl], 1] == 1) ||
                        (COMMOD9.IROWS[HPERM[scl], 1] == 11))
                    {
                        //draw full white/gold line for FADs and MAXsonly, to represent
                        //FAD-LAD pairs or FAD-MID-LAD triplets, or MAX-MIN pairs
                        brush = frm.MSG_BRUSH_WHITE;
                        pen = new Pen(brush);

                        if (COMMOD9.IROWS[HPERM[scl], 1] == 11)
                        {
                            brush = frm.MSG_BRUSH_14;
                            pen = new Pen(brush);
                        }

                        //they will be clipped to range length below
                        //other lines are blanks, awaiting a colored dash
                        //if this is the Ith taxon, vchange the line color
                        if ((trj == 0) && (COMMOD9.IROWS[HPERM[scl], 2] == I))
                        {
                            brush = frm.MSG_BRUSH_11;
                            pen = new Pen(brush);
                            Helper.GETEVNT(HPERM[scl], ref etitl, 1, 1, 0, 0, 0, 1);
                            g.TranslateTransform((int)(lft / 2), (int)(COMMOD9.maxy - btm));
                            g.RotateTransform(vert);
                            g.DrawString(etitl, frm.MSG_FONT_S, brush, 0, 0);
                            g.ResetTransform();
                        }

                        yreal = (double)(COMMOD9.IROWS[HPERM[scl], 0] + 1) * COMMOD9.YSPAN / COMMOD9.YROWS;

                        g.DrawLine(pen, lft, top + (int)(yreal), COMMOD9.maxx - rit, top + (int)(yreal));
                    }
                }

                //CPMS---------------------------------------------------------------------
                //CPMS    Clip the range lines
                //CPMS
                //CPMS    the horizontal position is given by IROWS(HPERM(scl),1
                //CPMS    the end to cut is given by IROWS(HPERM(scl),2
                //CPMS    the length of cut is given by position in HPERM (i.e. scl)
                brush = frm.MSG_BRUSH;
                pen = new Pen(brush);

                for (scl = 0; scl < COMMOD9.NEVNT; scl++)
                {
                    typsc = COMMOD9.IROWS[HPERM[scl], 1];
                    xreal = (double)(scl + 1) * COMMOD9.XSPAN / (double)(COMMOD9.NEVNT);
                    yreal = (double)(COMMOD9.IROWS[HPERM[scl], 0] + 1) * COMMOD9.YSPAN / COMMOD9.YROWS;
                    if ((typsc == 1) || (typsc == 11))
                    {
                        //paired event - FAD or MAX - cut from left
                        g.DrawLine(pen, lft, top + (int)(yreal), lft + (int)(xreal), top + (int)(yreal));
                    }
                    else if ((typsc == 2) || (typsc == 12))
                    {
                        // paired event - LAD or MIN - cut to right
                        g.DrawLine(pen, lft + (int)(xreal), top + (int)(yreal), COMMOD9.maxx - rit, top + (int)(yreal));
                    }
                    else if ((typsc >= 3) || (typsc < 1))
                    {
                        brush = frm.MSG_BRUSH_14;
                        pen = new Pen(brush);

                        if (typsc == 3)
                        {
                            brush = frm.MSG_BRUSH_12;
                            pen = new Pen(brush);
                        }

                        g.DrawLine(pen, lft + (int)(xreal) - 1, top + (int)(yreal), lft + (int)(xreal) + 1, top + (int)(yreal));

                        brush = frm.MSG_BRUSH;
                        pen = new Pen(brush);
                    }
                }
            }

            if (trj != 2)
            {
                //Add the legend and scales
                brush = frm.MSG_BRUSH_WHITE;

                xtitle = "TIME SCALE WITH ONE UNIT FOR EVERY OBSERVED EVENT";

                if (trj == 3)
                {
                    ytitle = "    Penalty vs Position of One Event in Sequence";
                }
                else
                {
                    ytitle = "TAXON NUMBER";
                }

                g.DrawString(xtitle.Trim(), frm.MSG_FONT_XS, brush, (int)(COMMOD9.maxx / 1.7), (int)(COMMOD9.maxy - btm / 1.9));

                if (trj == 3)
                {
                    Helper.GETEVNT(COMMOD9.XEVNT, ref xtitle, 1, 1, 1, 1, 1, 1);
                    brush = frm.MSG_BRUSH_10;
                    g.DrawString(xtitle.Trim(), frm.MSG_FONT_XS, brush, 5, (int)(COMMOD9.maxy - 32));
                }

                brush = frm.MSG_BRUSH_12;
                g.DrawString(COMMOD9.PROJNAME, frm.MSG_FONT_XS, brush, 5, (int)(COMMOD9.maxy - 12));
            }

            if (trj != 2)
            {
                brush = frm.MSG_BRUSH_WHITE;

                if (trj == 3) { brush = frm.MSG_BRUSH_10; }

                g.TranslateTransform((int)(lft / 2.7), (int)(COMMOD9.maxy - btm - 25));
                g.RotateTransform(vert);
                g.DrawString(ytitle.Trim(), frm.MSG_FONT_XS, brush, 0, 0);
                g.ResetTransform();

                if (COMMOD9.TRJGRF > 0 && trj == 1) { brush = frm.MSG_BRUSH_10; }

                WRITEPEN(frm, g, brush, 1);

            }

            if (trj != 2)
            {
                //CALL setgtextvector(INT2(0),INT2(1))??

                switch (COMMOD9.SOLVEF)
                {
                    case 4:
                    case 5:
                        frm.SetColor(1);
                        g.DrawString("Squeeze Penalty", frm.MSG_FONT_XS, frm.DW_Brush,
                            (int)(lft / 2.7), (int)(COMMOD9.maxy - btm - 240));
                        break;
                    case 6:
                    case 7:
                        frm.SetColor(1);
                        g.DrawString("Shrink Penalty", frm.MSG_FONT_XS, frm.DW_Brush,
                            (int)(lft / 2.7), (int)(COMMOD9.maxy - btm - 240));
                        break;
                    case 8:
                    case 9:
                        frm.SetColor(1);
                        g.DrawString("Tease (" + COMMOD9.STAKNAME + ") Penalty", frm.MSG_FONT_XS, frm.DW_Brush,
                            (int)(lft / 2.7), (int)(COMMOD9.maxy - btm - 240));
                        break;
                }

                if ((COMMOD9.SOLVEF != 2) && (COMMOD9.SOLVEF != 4) && (COMMOD9.SOLVEF != 6) &&
                    (COMMOD9.SOLVEF != 8))
                {
                    frm.SetColor(4);
                    g.TranslateTransform((int)(lft / 4), (int)(COMMOD9.maxy - btm - 190));
                    g.RotateTransform(vert);
                    g.DrawString("COOLING SCHEDULE", frm.MSG_FONT_XS, frm.DW_Brush, 0, 0);
                    g.ResetTransform();

                    g.DrawString("zero temp", frm.MSG_FONT_S, frm.DW_Brush, (int)(lft / 10), (int)(COMMOD9.maxy - btm));

                    if (COMMOD9.PAUSF == 5)
                    {
                        //track NTRIES
                        if (COMMOD9.NTRIES > 0)
                        {
                            COMMOD9.CNTRIES = COMMOD9.NTRIES;
                        }
                        else
                        {
                            COMMOD9.LSTRIES = COMMOD9.CNTRIES;
                        }

                        DRAWTEMP(frm, g);
                    }
                }

                frm.SetColor(15);
            }

            if (trj != 2)
            {

                if (trj < 2)
                {
                    //label every 10th taxon
                    for (scl = 9; scl < COMMOD9.NEVNT - COMMOD9.NSPC - COMMOD9.NMIDS; scl += 10)
                    {
                        yreal = (double)(scl + 1) * COMMOD9.YSPAN / COMMOD9.YROWS;

                        g.DrawString(string.Format("{0}", scl), frm.MSG_FONT_S, frm.DW_Brush,
                            lft - 25, top - (int)(yreal) - 5);
                    }
                }

                //CALL moveto(lft,top, xy)
            }

            if ((trj == 0) && (COMMOD9.PAUSF == 0))
            {
                //CALL NAVIKEY(I,NSPC,font,topfont,dinc,horscl,dum1,dum2,ltr)
                //IF((I.eq.0).or.(ltr.eq.'Q'))return;
                // GOTO 100
            }
        }
Exemple #3
0
        private void DRAWSCOR(frmCONOP frm, Graphics g, double xone, double xtwo, double yone, double ytwo, int side, int fill)
        {
            int prcnt, pnlty;

            //CPMS----------------------------------------------------------
            //c    xone yone     maximum value on given axis
            //c    xtwo ytwo     plotted value on given axis
            //c    side          symbol size
            //c    fill          filled symbol
            //CPMS----------------------------------------------------------

            prcnt = (int)(1000 * (xone - xtwo) / xone);
            pnlty = (int)(1000 * (yone - ytwo) / yone);

            if (fill == 1)
            {
                if (side == 0)
                {
                    g.DrawLine(frm.DW_Pen, newx(prcnt) - (int)side - 0.5f, newy(pnlty) - (int)side - 0.5f,
                        newx(prcnt) - (int)side + 0.5f, newy(pnlty) - (int)side + 0.5f);
                }
                else
                {
                    g.DrawRectangle(frm.DW_Pen, newx(prcnt) - (int)side, newy(pnlty) - (int)side,
                        (int)side * 2, (int)side * 2);
                }

            }
            else if (fill != 1)
            {
                if (side == 0)
                {
                    g.DrawLine(frm.DW_Pen, newx(prcnt) - (int)side - 0.5f, newy(pnlty) - (int)side - 0.5f,
                        newx(prcnt) - (int)side + 0.5f, newy(pnlty) - (int)side + 0.5f);
                }
                else
                {
                    g.FillRectangle(frm.DW_Brush, newx(prcnt) - (int)side, newy(pnlty) - (int)side,
                        (int)side * 2, (int)side * 2);
                }
            }
        }
        public void DO3(frmCONOP frm, Graphics g,ref int JDelta,ref int LDelta)
        {
            try
            {

                //CPMS------------------------------------------------------------------
                //c    Upon {Esc} the routine moves on to summary statistics screens
                //c    It is possible to move back and forth among these screens
                //c    but not to go back to the individual taxa, except via the
                //c    GRAPHICAL OUTPUT menu.
                //CPMS------------------------------------------------------------------
                //c     NOW plot the INCRALL totals in here
                //cpms  first, total INCRALL() into INCR()
                //cpms  and taxon count (richness!) into INCRN()
                //cpms  and section count from SINCRALL() into SINCRN()

                COMMOD COMMOD9 = COMMOD.Singleton();

                //CPMS     ----------------------------------------------
                //cpms  five loops
                //cpms      1st (L=2): plots number of taxa (richness!) at each level INCRN()
                //cpms      2nd (L=3): plots number of range increments at each level (sections and taxa) INCR()
                //cpms      3th (L=4): plots per-taxon increment count at each level INCREAL()
                //cpms      4th (L=5): plots per-section increment count at each level SINCREAL()
                //cpms      5rd (L=6): plots number of sections at each level SINCRN()
                //cpms  L starts at 2 to allow looping forward and backward
                //cpms  L goes to 0 only to exit loop

                L = 2 + LDelta;

                if (L > 0)
                {
                    //go to full screen view

                    //start with the ORDINAL composite (J) in order to use all events
                    //starting with the chosen composite causes too few event levels in histogram
                    J = COMMOD9.NSCT + 1 - 1 + JDelta;

                    //do not change composite section until requested by {{X}{+/-}} or {ESc}
                    if (J > COMMOD9.NSCT - 1)
                    {
                        g.Clear(frm.BackColor);

                        //draw the horizontal section bar--------------
                        g.FillRectangle(frm.MSG_BRUSH_7, COMMOD9.lft, COMMOD9.maxy - COMMOD9.btm,
                            COMMOD9.maxx - COMMOD9.rit - COMMOD9.lft, 10);

                        g.DrawRectangle(frm.DRAW_PEN, COMMOD9.lft, COMMOD9.maxy - COMMOD9.btm,
                            COMMOD9.maxx - COMMOD9.rit - COMMOD9.lft, 10);

                        //-----scale the section--------------------------
                        topx = COMMOD9.COMPLVL[COMMOD9.HLEVEL[J], J - COMMOD9.NSCT];//?
                        btmx = 1000;
                        scalx = (COMMOD9.maxx - COMMOD9.lft - COMMOD9.rit) / (topx - btmx);

                        //CPMS-----mark the collection levels--------------
                        for (K = 0; K <= COMMOD9.HLEVEL[J]; K++)
                        {
                            valx = COMMOD9.COMPLVL[K, J - COMMOD9.NSCT];

                            g.DrawLine(frm.DRAW_PEN, (int)(COMMOD9.lft + ((valx - btmx) * scalx)), (int)(COMMOD9.maxy - COMMOD9.btm + 10),
                                (int)(COMMOD9.lft + ((valx - btmx) * scalx)), (int)(COMMOD9.maxy - COMMOD9.btm + 13));
                        }

                        //Axis titles
                        //X-AXIS TITLE     do composite title
                        Output.COMPLBL(J + 1, ref xtitle);
                        g.RotateTransform(horiz);
                        g.DrawString(xtitle, frm.MSG_FONT, frm.MSG_BRUSH, (int)(COMMOD9.lft + (COMMOD9.maxx - COMMOD9.lft) / 2),
                            (int)(COMMOD9.maxy - COMMOD9.btm / 2));

                        //X-AXIS SUB-TITLE     do composite title
                        g.DrawString("[←] [→] keys reveal 4 more plots;   " +
                            "[↑] [↓] keys change composite scale;  " +
                            "[Esc] key exits loop", frm.MSG_FONT_S, frm.MSG_BRUSH, 10, (int)(COMMOD9.maxy - COMMOD9.btm / 2));

                        //Y-AXIS TITLE

                        if (L == 2)
                        {
                            ntitle = string.Format("{0}", Helper.MAXVal(INCRN));
                            ytitle = "   RAW TAXON RICHNESS:     i.e." +
                                " sum of observed partial ranges, at each level " +
                                "(not composite range-through ranges)";
                        }
                        else if (L == 3)
                        {
                            ntitle = string.Format("{0}", Helper.MAXVal(INCR));
                            ytitle = "    CUMULATIVE SUPPORT:     i.e. " +
                                " range increments summed across all taxa and sections";
                        }
                        else if (L == 4)
                        {
                            ntitle = string.Format("{0,6:0.00}", Helper.MAXVal(INCREAL));
                            ytitle = "   AVERAGE TAXON SUPPORT:     i.e. " +
                                "number of local range increments divided by " +
                                "number of taxa";
                        }
                        else if (L == 5)
                        {
                            ntitle = string.Format("{0,6:0.00}", Helper.MAXVal(SINCREAL));
                            ytitle = "   AVERAGE SECTION CONTRIBUTION:     i.e. " +
                                "number of local range increments divided by " +
                                "number of sections";
                        }
                        else if (L == 6)
                        {
                            ntitle = string.Format("{0}", Helper.MAXVal(SINCRN));
                            ytitle = "   SECTION RICHNESS:     i.e." +
                                " number of sections that contribute at least " +
                                "one partial range at each level";
                        }

                        g.TranslateTransform((int)(COMMOD9.lft / 4),
                            (int)(COMMOD9.maxy - COMMOD9.btm));
                        g.RotateTransform(vert);

                        Font strFont = new Font("Arial", 12);
                        SizeF strSize = g.MeasureString(ytitle, strFont);
                        while ((strSize.Width + (int)(COMMOD9.lft / 4) + 18) > COMMOD9.maxy)
                        {
                            strFont = new Font("Arial", strFont.Size - 1);
                            strSize = g.MeasureString(ytitle, strFont);
                        }

                        g.DrawString(ytitle, strFont, frm.MSG_BRUSH, 0, 0);
                        g.ResetTransform();

                        //Y-AXIS SUBTITLE
                        if (L == 2)
                        {
                            ytitle = "   uncorrected taxon count at each composite level";
                        }
                        else if (L == 3)
                        {
                            ytitle = "  increases with section count and taxon count";
                        }
                        else if (L == 4)
                        {
                            ytitle = "   average number of sections per taxon at each level";
                        }
                        else if (L == 5)
                        {
                            ytitle = "   average number of taxa per section at each level";
                        }
                        else if (L == 6)
                        {
                            ytitle = "   may be less than number of sections that span level";
                        }

                        g.TranslateTransform((int)(COMMOD9.lft / 2),
                            (int)(COMMOD9.maxy - COMMOD9.btm));
                        g.RotateTransform(-90);
                        g.DrawString(ytitle, frm.MSG_FONT_S, frm.MSG_BRUSH, 0, 0);
                        g.ResetTransform();

                        g.ResetTransform();
                        g.RotateTransform(horiz);
                        g.DrawString("max = " + ntitle, frm.MSG_FONT_S, frm.MSG_BRUSH, (int)(COMMOD9.lft / 4),
                            (int)(COMMOD9.top + 3));

                        g.ResetTransform();

                        //----------------------------------------------
                        //draw the histogram of sum of array values
                        //DO K=1,HLEVEL(J)  Not by levels, but by event: may be many events at one level!
                        for (K = 0; K < COMMOD9.NEVNT; K++)
                        {
                            if ((L == 2) && (INCRN[K] == 0)) continue;
                            if ((L == 3) && (INCR[K] == 0)) continue;
                            if ((L == 4) && (INCREAL[K] == 0.0)) continue;
                            if ((L == 5) && (SINCREAL[K] == 0.0)) continue;
                            if ((L == 6) && (SINCRN[K] == 0)) continue;

                            //NOTE: the following lines must use the complex HSCTSOL(BSTPERM(...
                            //      structure because only the ORDINAL composite has one level
                            //      for every event; the other composites tend to have fewer
                            //      levels because the zero-spacing collapses events into same
                            //      level.  Therefore, each event must 'find' its level in
                            //      each composite. (Only for the ORDINAL composite is the
                            //      array key equal to the level.)

                            //NOTE: To make the histogram bars contiguous, they should extend between
                            //       midpoints of adjacent event levels.  Therefore the code finds the
                            //       average of two levels and guards against (MAX, MIN) looking
                            //       beyond the section limits

                            valx = COMMOD9.COMPLVL[COMMOD9.HSCTSOL[COMMOD9.BSTPERM[K], J], J - COMMOD9.NSCT];
                            stepup = (COMMOD9.COMPLVL[Math.Min(COMMOD9.HLEVEL[J], COMMOD9.HSCTSOL[COMMOD9.BSTPERM[K + 1], J]), J - COMMOD9.NSCT] +
                                    COMMOD9.COMPLVL[COMMOD9.HSCTSOL[COMMOD9.BSTPERM[K], J], J - COMMOD9.NSCT]) / 2.00;
                            stepdn = (COMMOD9.COMPLVL[COMMOD9.HSCTSOL[COMMOD9.BSTPERM[K], J], J - COMMOD9.NSCT] +
                                COMMOD9.COMPLVL[Math.Max(0, COMMOD9.HSCTSOL[COMMOD9.BSTPERM[K - 1], J]), J - COMMOD9.NSCT]) / 2.00;

                            //scale histogram bar to number of counts in INCR() for L.eq.1
                            //or to average count in INCREAL() for L.eq.2
                            //and to space between composite sections and composite range
                            if ((int)(COMMOD9.lft + ((stepup - btmx) * scalx)) < 1) continue;

                            if (L == 2)
                            {
                                int x1 = (int)(COMMOD9.lft + ((stepup - btmx)) * scalx);
                                int y1 = (int)(COMMOD9.maxy - COMMOD9.btm - 1);
                                int x2 = (int)(COMMOD9.lft + ((stepdn - btmx)) * scalx);
                                int y2 = (int)((double)(COMMOD9.maxy - COMMOD9.btm - 1) - ((double)(COMMOD9.maxy - COMMOD9.top - COMMOD9.btm - 1) *
                                    (double)(INCRN[K]) / (double)(Helper.MAXVal(INCRN))));

                                g.FillRectangle(frm.MSG_BRUSH_CCFFCC, Math.Min(x1, x2), Math.Min(y1, y2),
                                    Math.Abs(x1 - x2), Math.Abs(y1 - y2));
                            }
                            else if (L == 3)
                            {
                                int x1 = (int)(COMMOD9.lft + ((stepup - btmx)) * scalx);
                                int y1 = (int)(COMMOD9.maxy - COMMOD9.btm - 1);
                                int x2 = (int)(COMMOD9.lft + ((stepdn - btmx)) * scalx);
                                int y2 = (int)((double)(COMMOD9.maxy - COMMOD9.btm - 1) - ((double)(COMMOD9.maxy - COMMOD9.top - COMMOD9.btm - 1) *
                                    (double)(INCR[K]) / (double)(Helper.MAXVal(INCR))));

                                g.FillRectangle(frm.MSG_BRUSH_CCCCFF, Math.Min(x1, x2), Math.Min(y1, y2),
                                    Math.Abs(x1 - x2), Math.Abs(y1 - y2));
                            }
                            else if (L == 4)
                            {
                                int x1 = (int)(COMMOD9.lft + ((stepup - btmx)) * scalx);
                                int y1 = (int)(COMMOD9.maxy - COMMOD9.btm - 1);
                                int x2 = (int)(COMMOD9.lft + ((stepdn - btmx)) * scalx);
                                int y2 = (int)((double)(COMMOD9.maxy - COMMOD9.btm - 1) - ((double)(COMMOD9.maxy - COMMOD9.top - COMMOD9.btm - 1) *
                                    (double)(INCREAL[K]) / (double)(Helper.MAXVal(INCREAL))));

                                g.FillRectangle(frm.MSG_BRUSH_CCCCFF, Math.Min(x1, x2), Math.Min(y1, y2),
                                    Math.Abs(x1 - x2), Math.Abs(y1 - y2));
                            }
                            else if (L == 5)
                            {
                                int x1 = (int)(COMMOD9.lft + ((stepup - btmx)) * scalx);
                                int y1 = (int)(COMMOD9.maxy - COMMOD9.btm - 1);
                                int x2 = (int)(COMMOD9.lft + ((stepdn - btmx)) * scalx);
                                int y2 = (int)((double)(COMMOD9.maxy - COMMOD9.btm - 1) - ((double)(COMMOD9.maxy - COMMOD9.top - COMMOD9.btm - 1) *
                                    (double)(SINCREAL[K]) / (double)(Helper.MAXVal(SINCREAL))));

                                g.FillRectangle(frm.MSG_BRUSH_FFCCCC, Math.Min(x1, x2), Math.Min(y1, y2),
                                    Math.Abs(x1 - x2), Math.Abs(y1 - y2));
                            }
                            else if (L == 6)
                            {
                                int x1 = (int)(COMMOD9.lft + ((stepup - btmx)) * scalx);
                                int y1 = (int)(COMMOD9.maxy - COMMOD9.btm - 1);
                                int x2 = (int)(COMMOD9.lft + ((stepdn - btmx)) * scalx);
                                int y2 = (int)((double)(COMMOD9.maxy - COMMOD9.btm - 1) - ((double)(COMMOD9.maxy - COMMOD9.top - COMMOD9.btm - 1) *
                                    (double)(SINCRN[K]) / (double)(Helper.MAXVal(SINCRN))));

                                g.FillRectangle(frm.MSG_BRUSH_FFCCCC, Math.Min(x1, x2), Math.Min(y1, y2),
                                    Math.Abs(x1 - x2), Math.Abs(y1 - y2));
                            }

                        }//End for K

                        //scale the y-axis
                        g.DrawLine(frm.DRAW_PEN, (int)(COMMOD9.lft), (int)(COMMOD9.maxy - COMMOD9.btm),
                            (int)(COMMOD9.lft), (int)(COMMOD9.maxy - COMMOD9.btm + 2));

                        g.DrawLine(frm.DRAW_PEN, (int)(COMMOD9.lft), (int)(COMMOD9.maxy - COMMOD9.btm),
                           (int)(COMMOD9.lft), (int)(COMMOD9.top));

                        //set appropriate top value
                        if (L == 2)
                        {
                            MAXYVAL = (double)(Helper.MAXVal(INCRN));
                        }
                        else if (L == 3)
                        {
                            MAXYVAL = (double)(Helper.MAXVal(INCR));
                        }
                        else if (L == 4)
                        {
                            MAXYVAL = (double)(Helper.MAXVal(INCREAL));
                        }
                        else if (L == 5)
                        {
                            MAXYVAL = (double)(Helper.MAXVal(SINCREAL));
                        }
                        else if (L == 6)
                        {
                            MAXYVAL = (double)(Helper.MAXVal(SINCRN));
                        }

                        N = 1;
                        while ((double)N < MAXYVAL)
                        {
                            g.DrawLine(frm.DRAW_PEN, (int)(COMMOD9.lft), (int)((double)(COMMOD9.maxy - COMMOD9.btm) -
                                (double)(N) * (COMMOD9.maxy - COMMOD9.btm - COMMOD9.top) / MAXYVAL),
                            (int)(COMMOD9.lft - 5), (int)((double)(COMMOD9.maxy - COMMOD9.btm) -
                                (double)(N) * (COMMOD9.maxy - COMMOD9.btm - COMMOD9.top) / MAXYVAL));

                            //limit number of scale ticks

                            if (MAXYVAL <= 50)
                            {
                                N++;
                            }
                            else if (MAXYVAL <= 100)
                            {
                                N += 10;
                            }
                            else if (MAXYVAL <= 500)
                            {
                                N += 50;
                            }
                            else if (MAXYVAL <= 1000)
                            {
                                N += 100;
                            }
                            else if (MAXYVAL <= 10000)
                            {
                                N += 500;
                            }
                        }
                    }

                    S = 0;
                }
            }
            catch
            { }
        }
Exemple #5
0
        private void DASH(frmCONOP frm, Graphics g, double xrl, double yrl)
        {
            COMMOD COMMOD9 = COMMOD.Singleton();
            int scl = 0;
            int top = 0;
            int btm = 50;
            int lft = 100;
            int rit = 0;

            g.DrawLine(frm.DW_Pen, lft + (int)xrl - 1, top + (int)yrl, lft + (int)(xrl) + 1, top + (int)(yrl));
        }
Exemple #6
0
        private void NEWDASH(frmCONOP frm, Graphics g, int rnki, int rnkj, int rnkt, int cl1, int cl2)
        {
            COMMOD COMMOD9 = COMMOD.Singleton();
            double xrl, yrl;
            //CPMS---------------------------------------------------
            //CPMS  Used for MID events that always lie in a white range!
            //CPMS  other unpaired events must be BLACKED out
            //CPMS  rnki - the old dash position in range
            //CPMS  rnkj - the key to event (row) number
            //CPMS  rnkt - and the new dash position
            xrl = 0.0;
            yrl = 0.0;
            //cpms  fix the row to modify
            yrl = (double)((COMMOD9.IROWS[COMMOD9.LSTPERM[rnkj], 0] + 1) * COMMOD9.YSPAN / COMMOD9.YROWS);
            //white-out/blackout the old dash
            xrl = (double)(rnki + 1) * COMMOD9.XSPAN / (double)COMMOD9.NEVNT;

            frm.SetColor(cl1);
            DASH(frm, g, xrl, yrl);

            //draw the new red dash
            xrl = (double)(rnkt + 1) * COMMOD9.XSPAN / (double)COMMOD9.NEVNT;
            frm.SetColor(cl2);
            DASH(frm, g, xrl, yrl);

            frm.SetColor(15);
        }
Exemple #7
0
        //Draws the x-axis
        private void XSCALE(frmCONOP frm, Graphics g, int xbig, int mxx, int mxy, int xlft, int xrit, int y)
        {
            //COMMOD COMMOD9=COMMOD.Singleton();

            int stp, jmp, lbl, tck;
            double xreal, fctr;
            //cpms  DEC fortran does not handle reals and integers like MS Fortran
            //cpms  so we scale the x-axis position in reals and then apply INT2()
            //cpms  when performing a lineto or moveto!
            string xtitle = "";

            //C-------------------------------------------------------------------
            //CPMS	  scale line runs from xlft to maxx-xrit; everywhere at maxy-y
            //CPMS	  the biggest x value is xbig (e.g. NEVNT)
            //C---------------------------------------------
            //CPMS  Draw the x-axis baseline
            g.DrawLine(frm.DRAW_PEN_WHITE, xlft, mxy - y, mxx - xrit, mxy - y);

            //CPMS----------------------------
            //CPMS	Scale the ticks and labels
            if (xbig < 200)
            {
                jmp = 1;
                lbl = 20;
            }
            else if (xbig < 400)
            {
                jmp = 2;
                lbl = 50;
            }
            else if (xbig < 800)
            {
                jmp = 5;
                lbl = 100;
            }
            else if (xbig < 1600)
            {
                jmp = 10;
                lbl = 200;
            }
            else
            {
                jmp = 20;
                lbl = 500;
            }

            //CPMS----------------
            //cpms  determine scale factor to use in next two loops
            fctr = (double)(mxx - xlft - xrit) / (double)(xbig);
            //cpms----------------
            //CPMS  Draw the ticks
            for (stp = 0; stp <= xbig; stp += jmp)
            {
                xreal = (double)(stp) * fctr;

                //determine tick height
                if (stp % 100 == 0)
                {
                    tck = 8;
                }
                else if (stp % 50 == 0)
                {
                    tck = 6;
                }
                else if (stp % 10 == 0)
                {
                    tck = 4;
                }
                else
                {
                    tck = 2;
                }

                g.DrawLine(frm.DRAW_PEN_WHITE, xlft + (int)(xreal), mxy - y, xlft + (int)(xreal), mxy - y + tck);
            }

            //CPMS-----------------
            //CPMS	Draw the lables
            for (stp = lbl; stp <= xbig; stp += lbl)
            {
                xreal = (double)(stp) * fctr;
                g.DrawString(string.Format("{0}", stp), frm.MSG_FONT_S, frm.MSG_BRUSH_WHITE, xlft - 15 + (int)(xreal), mxy - y + 10);

            }
        }
        public void DO2(frmCONOP frm, Graphics g, ref int JDelta, ref int evtDelta)
        {
            try
            {
                COMMOD COMMOD9 = COMMOD.Singleton();
                Helper.SetVal(INCR, 0);
                //set up two loops
                //first loop scans automatically through all taxa
                //second loop is under manual control
                //Note: outer loop is not indented
                for (M = 2; M <= 2; M++)
                {
                    if (evtDelta == 0)
                    {
                        font = 1;
                        topfont = 1;
                        dinc = 0;
                        horscl = 0;
                        COMMOD9.XEVNT = 0;//<=HXD?

                        I = 0;//<=HXD?
                        J = 0;//<=HXD?
                        K = 0;//<=HXD?
                        S = 1;//<=HXD?<=HXD
                        L = 0;//<=HXD?

                        Nfit = 50;

                        //CPMS---------------------------------------------------------
                        //CPMS  Consider only the composite sections
                        //cpms  go to the first taxon in the best permutation
                        //c     do not change composite section until requested by {+/-}
                        I = COMMOD9.BSTPERM[0];

                        //CPMS  do only FAD/MAXs and unpaired events
                        //CPMS  find the highest non-LAD/MIN it replaces NEVNT
                        //cpms  as the limiting upsection scan
                        K = COMMOD9.NEVNT - 1;
                        while ((COMMOD9.IROWS[COMMOD9.BSTPERM[K], 1] == 2) || (COMMOD9.IROWS[COMMOD9.BSTPERM[K], 1] == 12))
                        {
                            K = K - 1;
                        }
                        TOPEVT = K;

                        COMPFmem = COMMOD9.COMPF;
                        COMMOD9.COMPF = 1;  // over-ride COMPF for duration of this routine
                        J = COMMOD9.NSCT - 1 + COMMOD9.COMPF+JDelta;//<=HXD
                        Jcst = COMMOD9.NSCT - 1 + COMPFmem;////<=HXD

                        if (M == 1) { }
                    }

                    if (J > COMMOD9.NSCT - 1)//<=HXD
                    {

                        if (evtDelta != 0)
                        {
                            K = L;
                            L = evtDelta;

                            if (L < K)
                            {
                                while ((COMMOD9.IROWS[COMMOD9.BSTPERM[L], 1] == 2) || (COMMOD9.IROWS[COMMOD9.BSTPERM[L], 1] == 12))
                                {
                                    L = L - 1;
                                    if (L < 0) L = TOPEVT;
                                    upsection = false;
                                }
                            }
                            else if (L > K)
                            {
                                while ((COMMOD9.IROWS[COMMOD9.BSTPERM[L], 1] == 2) || (COMMOD9.IROWS[COMMOD9.BSTPERM[L], 1] == 12))
                                {
                                    L = L + 1;
                                    if (L > TOPEVT)
                                        L = 0;
                                }
                            }

                            evtDelta = L;
                        }

                        g.Clear(frm.BackColor);

                        topf = false;
                        basf = false;

                        //CPMS-----draw the horizontal section bar--------------
                        g.FillRectangle(frm.MSG_BRUSH_7, COMMOD9.lft, COMMOD9.maxy - COMMOD9.btm,
                            COMMOD9.maxx - COMMOD9.rit - COMMOD9.lft, 10);

                        g.DrawRectangle(frm.DRAW_PEN, COMMOD9.lft, COMMOD9.maxy - COMMOD9.btm,
                            COMMOD9.maxx - COMMOD9.rit - COMMOD9.lft, 10);

                        //CPMS-----scale the section--------------------------
                        topx = COMMOD9.COMPLVL[COMMOD9.HLEVEL[J], J - COMMOD9.NSCT];//?
                        btmx = 1000;
                        scalx = (COMMOD9.maxx - COMMOD9.lft - COMMOD9.rit) / (topx - btmx);

                        //CPMS-----mark the collection levels--------------
                        for (K = 0; K <= COMMOD9.HLEVEL[J]; K++)
                        {
                            valx = COMMOD9.COMPLVL[K, J - COMMOD9.NSCT];

                            g.DrawLine(frm.DRAW_PEN, (int)(COMMOD9.lft + ((valx - btmx) * scalx)), (int)(COMMOD9.maxy - COMMOD9.btm + 10),
                                (int)(COMMOD9.lft + ((valx - btmx) * scalx)), (int)(COMMOD9.maxy - COMMOD9.btm + 13));
                        }

                        //CPMS  a needless mirror in the custom composite
                        for (K = 0; K <= COMMOD9.HLEVEL[Jcst]; K++)
                        {
                            valcx = COMMOD9.COMPLVL[K, Jcst - COMMOD9.NSCT];
                        }

                        //CPMS-----draw the composite event range--------------
                        I = COMMOD9.BSTPERM[L];
                        S = COMMOD9.NSCT + 2 - 1;
                        //label the current event on the graph
                        EVNTLBLINC(frm, g, I, J);

                        if (((COMMOD9.IROWS[I, 1] > 2) && (COMMOD9.IROWS[I, 1] < 11)) || (COMMOD9.IROWS[I, 1] < 1))
                        {
                            //CPMS  if the event was observed, draw black dash
                            if (COMMOD9.ISTATIC[I, J, 0] > -1)//<=HXD
                            {
                                valx = COMMOD9.COMPLVL[COMMOD9.ISTATIC[I, J, 0], J - COMMOD9.NSCT];
                                valcx = COMMOD9.COMPLVL[COMMOD9.ISTATIC[I, Jcst, 0], Jcst - COMMOD9.NSCT];
                                RANGEBARINC(frm, g, frm.DRAW_PEN, valx, valx, (S + 1), COMMOD9.NSCT, btmx, scalx, 1, basf, topf);//<=HXD
                            }
                        }
                        else if (COMMOD9.IROWS[I, 1] == 1)//IF a FAD (oldest of a stretching pair)
                        {
                            ac = COMMOD9.ISTATIC[I, J, 0];
                            bc = COMMOD9.ISTATIC[COMMOD9.IROWS[I, 3], J, 0];
                            acst = COMMOD9.ISTATIC[I, Jcst, 0];
                            bcst = COMMOD9.ISTATIC[COMMOD9.IROWS[I, 3], Jcst, 0];

                            if (ac > -1)
                            {
                                //If observed! this is a composite; must be observed!
                                //store composite range
                                valc = COMMOD9.COMPLVL[ac, J - COMMOD9.NSCT];
                                val2c = COMMOD9.COMPLVL[bc, J - COMMOD9.NSCT];
                                valdif = val2c - valc;
                                valcst = COMMOD9.COMPLVL[ac, Jcst - COMMOD9.NSCT];
                                val2cst = COMMOD9.COMPLVL[bc, Jcst - COMMOD9.NSCT];

                                //draw black range
                                RANGEBARINC(frm, g, frm.DRAW_PEN, valc, val2c, (S + 1), COMMOD9.NSCT, btmx, scalx, 1, basf, topf);//<=HXD
                            }
                        }
                        else if (COMMOD9.IROWS[I, 1] == 11)//IF a MAX (older of a shrinking pair)
                        {
                            ac = COMMOD9.ISTATIC[I, J, 0];
                            bc = COMMOD9.ISTATIC[COMMOD9.IROWS[I, 3], J, 0];
                            acst = COMMOD9.ISTATIC[I, Jcst, 0];
                            bcst = COMMOD9.ISTATIC[COMMOD9.IROWS[I, 3], Jcst, 0];

                            if (ac > -1)
                            {
                                //If observed! this is a composite; must be observed!
                                //store composite range
                                valc = COMMOD9.COMPLVL[ac, J - COMMOD9.NSCT];
                                val2c = COMMOD9.COMPLVL[bc, J - COMMOD9.NSCT];
                                valdif = val2c - valc;
                                valcst = COMMOD9.COMPLVL[ac, Jcst - COMMOD9.NSCT];
                                val2cst = COMMOD9.COMPLVL[bc, Jcst - COMMOD9.NSCT];

                                //draw black range
                                RANGEBARINC(frm, g, frm.DRAW_PEN, valc, val2c, (S + 1), COMMOD9.NSCT, btmx, scalx, 1, basf, topf);//<=HXD

                            }
                        }

                        g.DrawString("COMPOSITE", frm.MSG_FONT_S, frm.MSG_BRUSH,
                            6, (int)(COMMOD9.top - 6 + (S + 1) * (COMMOD9.maxy - COMMOD9.top - (COMMOD9.btm * 5)) / (double)(COMMOD9.NSCT + 2)));//<=HXD

                        //----------------------------------------
                        //draw the individual section event ranges

                        //count the number of range bars
                        //if NSCT is large
                        if (COMMOD9.NSCT <= Nfit)
                        {
                            NLOCL = COMMOD9.NSCT;
                            Slocl = COMMOD9.NSCT;
                        }
                        else
                        {
                            Slocl = 0;
                            NLOCL = 0;

                            for (S = 0; S < COMMOD9.NSCT; S++)
                            {
                                if (COMMOD9.ISTATIC[I, S, 0] > -1) NLOCL++;
                            }
                        }

                        for (S = 0; S < COMMOD9.NSCT; S++)//START-DO-S-loop  sections 1 to NSCT
                        {
                            topf = false;
                            basf = false;
                            // If unpaired MID
                            // IF(IROWS(I,2).eq.3) THEN
                            //  do nothing; should not get this far
                            //  should already have responded to prior cycle
                            //   CYCLE casues trouble - continuous looping
                            //ELSEIF unpaired (not FAD-LAD or MAX-MIN)

                            if (((COMMOD9.IROWS[I, 1] > 2) && (COMMOD9.IROWS[I, 1] < 11)) || (COMMOD9.IROWS[I, 1] < 1))
                            {
                                //if the event was observed, draw black dash
                                if (COMMOD9.ISTATIC[I, S, 0] == -1)
                                {
                                    continue;
                                }
                                else
                                {
                                    if (COMMOD9.NSCT > Nfit)
                                    {
                                        Slocl++;
                                    }
                                    else
                                    {
                                        Slocl = S + 1;//<=?
                                    }

                                    valx = COMMOD9.COMPLVL[COMMOD9.ISTATIC[I, J, 0], J - COMMOD9.NSCT];
                                    val2x = valx;
                                    valcx = COMMOD9.COMPLVL[COMMOD9.ISTATIC[I, Jcst, 0], Jcst - COMMOD9.NSCT];
                                    val2cx = valcx;

                                    RANGEBARINC(frm, g, frm.DRAW_PEN_12, valx, val2x, Slocl, NLOCL, btmx, scalx, 0, basf, topf);

                                }
                            }
                            else if ((COMMOD9.IROWS[I, 1] == 1) || (COMMOD9.IROWS[I, 1] == 11)) //IF a FAD or a MAX
                            {
                                ax = COMMOD9.ISTATIC[I, S, 0];
                                if (ax <= -1) continue;//<=HXD
                                if (COMMOD9.NSCT > Nfit)
                                {
                                    Slocl++;
                                }
                                else
                                {
                                    Slocl = S+1;//<=?
                                }

                                alphx = (int)(COMMOD9.HSCTSOL[I, S]);
                                //locate observed LAD/MIN level
                                bx = COMMOD9.ISTATIC[COMMOD9.IROWS[I, 3], S, 0];
                                betax = (int)(COMMOD9.HSCTSOL[COMMOD9.IROWS[I, 3], S]);

                                //Examine possible three possible configurations
                                //for each end of observed range
                                //__________
                                //FIND CMPAX
                                if (ax == alphx)
                                {
                                    //CASE 1: FAD/MAX not adjusted; i.e. on LOC
                                    cmpax = ac;
                                    cstax = acst;
                                    valx = COMMOD9.COMPLVL[cmpax, J - COMMOD9.NSCT];
                                    valcx = COMMOD9.COMPLVL[cstax, Jcst - COMMOD9.NSCT];
                                }
                                else
                                {
                                    for (K = 0; K < COMMOD9.NEVNT + 1; K++)
                                    {
                                        if (K == L) continue;
                                        if (K > COMMOD9.NEVNT - 1) break;

                                        if ((COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], S, 0] == ax) &&
                                            (COMMOD9.HSCTSOL[COMMOD9.BSTPERM[K], S] == ax))
                                        {
                                            //----CASE 2. FAD/MAX adjusted, another event at FAD/MAX-level is unadjusted)
                                            cmpax = COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], J, 0];
                                            cstax = COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], Jcst, 0];
                                            valx = COMMOD9.COMPLVL[cmpax, J - COMMOD9.NSCT];
                                            valcx = COMMOD9.COMPLVL[cstax, Jcst - COMMOD9.NSCT];
                                            break;
                                        }
                                    }

                                    if (K > COMMOD9.NEVNT - 1)
                                    {
                                        //----CASE 3: FAD/MAX adjusted; no event at FA/MAXD-level lies on LOC
                                        //place level between next lower and higher composite levels
                                        //divide according to number of events in between?
                                        //try half-way first
                                        lvlunder = 0;
                                        lvlover = 0;
                                        lvlcunder = 0;
                                        lvlcover = 0;

                                        for (K = 0; K < COMMOD9.NEVNT; K++)
                                        {
                                            if (COMMOD9.HSCTSOL[COMMOD9.BSTPERM[K], S] < ax)
                                            {
                                                lvlunder = COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], J, 0];
                                                lvlcunder = COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], Jcst, 0];
                                            }
                                            else if (COMMOD9.HSCTSOL[COMMOD9.BSTPERM[K], S] > ax)
                                            {
                                                lvlover = COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], J, 0];
                                                lvlcover = COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], Jcst, 0];
                                                cmpax = (lvlunder + lvlover + 2) / 2;//<=?
                                                cstax = (lvlcunder + lvlcover + 2) / 2;//<=?
                                                valx = (COMMOD9.COMPLVL[lvlunder, J - COMMOD9.NSCT] +
                                                    COMMOD9.COMPLVL[lvlover, J - COMMOD9.NSCT]) / 2;
                                                valcx = (COMMOD9.COMPLVL[lvlcunder, Jcst - COMMOD9.NSCT] +
                                                    COMMOD9.COMPLVL[lvlcover, Jcst - COMMOD9.NSCT]) / 2;

                                                break;
                                            }
                                        }

                                        if (K > COMMOD9.NEVNT - 1) continue;

                                    }
                                }

                                //CASE BASE: FA/MAXD at section base
                                //would be placed at composite default by default
                                //move to age of section base
                                if (ax == 0)//attempt to place at composite age of section base
                                {
                                    basf = true;
                                    //DOES NOT YET WORK CONSISTENTLY [see also LIMITS() in CONOP.FOR]
                                    cmpax = COMMOD9.ISTATIC[COMMOD9.LIMITS[S, 0], J, 0];
                                    cstax = COMMOD9.ISTATIC[COMMOD9.LIMITS[S, 0], Jcst, 0];
                                    valbx = COMMOD9.COMPLVL[COMMOD9.ISTATIC[COMMOD9.LIMITS[S, 0], J, 0], J - COMMOD9.NSCT];
                                    valbcx = COMMOD9.COMPLVL[COMMOD9.ISTATIC[COMMOD9.LIMITS[S, 0], Jcst, 0], Jcst - COMMOD9.NSCT];
                                }

                                //__________
                                //FIND CMPBX
                                if (bx == betax)
                                {
                                    //----CASE 4: LAD/MIN not adjusted; i.e. on LOC
                                    cmpbx = bc;
                                    cstbx = bcst;
                                    val2x = COMMOD9.COMPLVL[cmpbx, J - COMMOD9.NSCT];
                                    val2cx = COMMOD9.COMPLVL[cstbx, Jcst - COMMOD9.NSCT];
                                }
                                else
                                {
                                    for (K = COMMOD9.NEVNT - 1; K >= -1; K--)
                                    {
                                        if (K == COMMOD9.IROWS[L, 3]) continue;
                                        if (K < 0) break;
                                        if ((COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], S, 0] == bx) &&
                                            (COMMOD9.HSCTSOL[COMMOD9.BSTPERM[K], S] == bx))
                                        {
                                            //----CASE 5: LAD/MIN adjusted, another event at LAD/MIN-level is unadjusted)
                                            cmpbx = COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], J, 0];
                                            cstbx = COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], Jcst, 0];
                                            val2x = COMMOD9.COMPLVL[cmpbx, J - COMMOD9.NSCT];
                                            val2cx = COMMOD9.COMPLVL[cstbx, Jcst - COMMOD9.NSCT];
                                            break;
                                        }
                                    }

                                    if (K < 0)
                                    {
                                        //----CASE 6: LAD/MIN adjusted; no event at LAD/MIN-level lies on LOC
                                        //place level between next lower and higher composite levels
                                        //divide according to number of events in between?
                                        //try half-way first
                                        lvlunder = COMMOD9.HLEVEL[J];
                                        lvlover = COMMOD9.HLEVEL[J];
                                        lvlcunder = COMMOD9.HLEVEL[J];
                                        lvlcover = COMMOD9.HLEVEL[J];

                                        for (K = COMMOD9.NEVNT-1; K >= 0; K--)
                                        {
                                            if (COMMOD9.HSCTSOL[COMMOD9.BSTPERM[K], S] > bx)
                                            {
                                                lvlover = COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], J, 0];
                                                lvlcover = COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], Jcst, 0];
                                            }
                                            else if (COMMOD9.HSCTSOL[COMMOD9.BSTPERM[K], S] < bx)
                                            {
                                                lvlunder = COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], J, 0];
                                                lvlcunder = COMMOD9.ISTATIC[COMMOD9.BSTPERM[K], Jcst, 0];
                                                cmpbx = (lvlunder + lvlover + 2) / 2;//<=?
                                                cstbx = (lvlcunder + lvlcover + 2) / 2;//<=?
                                                val2x = (COMMOD9.COMPLVL[lvlunder, J - COMMOD9.NSCT] +
                                                    COMMOD9.COMPLVL[lvlover, J - COMMOD9.NSCT]) / 2;
                                                val2cx = (COMMOD9.COMPLVL[lvlcunder, Jcst - COMMOD9.NSCT] +
                                                    COMMOD9.COMPLVL[lvlcover, Jcst - COMMOD9.NSCT]) / 2;
                                                break;
                                            }
                                        }

                                        if (K < 0) continue;
                                    }
                                }

                                //CASE TOP. LAD/MIN at section top
                                if (bx == COMMOD9.HLEVEL[S])
                                {
                                    topf = true;
                                    //attempt to place at composite age of section top
                                    //DOES NOT YET WORK CONSISTENTLY [see also LIMITS() in CONOP.FOR]
                                    cmpbx = COMMOD9.ISTATIC[COMMOD9.LIMITS[S, 1], J, 0];
                                    cstbx = COMMOD9.ISTATIC[COMMOD9.LIMITS[S, 1], Jcst, 0];
                                    valtx = COMMOD9.COMPLVL[COMMOD9.ISTATIC[COMMOD9.LIMITS[S, 1], J, 0], J - COMMOD9.NSCT];
                                    valtcx = COMMOD9.COMPLVL[COMMOD9.ISTATIC[COMMOD9.LIMITS[S, 1], Jcst, 0], Jcst - COMMOD9.NSCT];
                                }

                                //clean up the open-ended top
                                if (topf)
                                {
                                    if (valtx < valx)
                                    {
                                        val2x = valx;
                                    }
                                    else
                                    {
                                        val2x = valtx;
                                    }

                                    if (valtcx < valcx)
                                    {
                                        val2cx = valcx;
                                    }
                                    else
                                    {
                                        val2cx = valtcx;
                                    }
                                }

                                //clean up the open-ended base
                                if (basf)
                                {
                                    if (valbx > val2x)
                                    {
                                        valx = val2x;
                                    }
                                    else
                                    {
                                        valx = valbx;
                                    }

                                    if (valbcx > val2cx)
                                    {
                                        valcx = val2cx;
                                    }
                                }

                                //Set default Icon and adjust if needed
                                Icon = "+++++";
                                if (basf && topf)
                                {
                                    Icon = "<+++>";
                                }
                                else if (basf)
                                {
                                    Icon = "<++++";
                                }
                                else if (topf)
                                {
                                    Icon = "++++>";
                                }

                                if (COMMOD9.IROWS[I, 1] == 1)
                                {// red for local taxon ranges
                                    RANGEBARINC(frm, g, frm.DRAW_PEN_12, valx, val2x, Slocl, NLOCL, btmx, scalx, 0, basf, topf);
                                }
                                else if (COMMOD9.IROWS[I, 1] == 11)
                                {// dark red for local uncertainty intervals
                                    RANGEBARINC(frm, g, frm.DRAW_PEN_4, valx, val2x, Slocl, NLOCL, btmx, scalx, 0, basf, topf);
                                }
                                else
                                {//grey for unpaired events (default)
                                    RANGEBARINC(frm, g, frm.DRAW_PEN_8, valx, val2x, Slocl, NLOCL, btmx, scalx, 0, basf, topf);
                                }

                                if ((COMMOD9.IROWS[I, 1] != 11) && (COMMOD9.IROWS[I, 1] != 12))
                                {
                                    // - should not be necessry to check for 12 (MIN)
                                    //load FAD and LAD positions to GRAND

                                    if ((M == 1) && (J == (COMMOD9.NSCT + COMMOD9.COMPF - 1)))
                                    {
                                        valdif = val2c - valc;
                                        //proportional distance of local FAD up into range
                                        //scaled to 100 units and based at 100
                                        if (valx < valc)
                                        {
                                            IG = 99;
                                        }
                                        else if (valx == valc)
                                        {
                                            IG = 100;
                                        }
                                        else if (valx == val2c)
                                        {
                                            IG = 200;
                                        }
                                        else if (valx > val2c)
                                        {
                                            IG = 201;
                                        }
                                        else
                                        {
                                            IG = (int)((double)(valx - valc) * 100.0 / (double)(valdif)) + 100;
                                        }

                                        if (!basf) GRAND[IG]++;
                                        //proportional distance of local LAD up into range
                                        //scaled to 100 units and based at 300

                                        if (val2x < valc)
                                        {
                                            KG = 299;
                                        }
                                        else if (val2x == valc)
                                        {
                                            KG = 300;
                                        }
                                        else if (val2x == val2c)
                                        {
                                            KG = 400;
                                        }
                                        else if (val2x > val2c)
                                        {
                                            KG = 401;
                                        }
                                        else
                                        {
                                            KG = 400 - (int)((double)(val2c - val2x) * 100.0 / (double)(valdif));
                                        }

                                        if (!topf) GRAND[KG]++;
                                    }
                                }
                            }

                            g.DrawString(COMMOD9.SECTNICK[S].Trim(), frm.MSG_FONT_S, frm.MSG_BRUSH,
                                (int)(COMMOD9.lft / 2),
                                (int)(COMMOD9.top - 6 + Slocl * (COMMOD9.maxy - COMMOD9.top - (COMMOD9.btm * 5)) / (double)(NLOCL + 2)));

                            //add current section to the increment array
                            //by taxon and by section
                            //NOT for MAX-MIN pairs

                            if ((COMMOD9.IROWS[I, 1] != 11) && (COMMOD9.IROWS[I, 1] != 12))
                            {
                                for (K = Math.Min(cmpax, cmpbx); K <= Math.Max(cmpax, cmpbx); K++)
                                {
                                    INCR[K]++;
                                    if (!(SPCSCT[COMMOD9.IROWS[I, 2], S])) SINCRALL[S, K]++;
                                    //note - because we loop though all sections for each taxon
                                    //INCR can be loaded to INCRALL later to avoid duplicates
                                    //SINCRALL must track duplicates differently because no section
                                    //is complete until all taxa are completed; hence use of LOGICAL
                                    //array SPCSCT(), which is a good generic array and might be moved
                                    //to CONMOD for access by all routines.
                                }

                                //note: loop through entire partial range before setting SPCSCT flag!
                                SPCSCT[COMMOD9.IROWS[I, 2], S] = true;
                            }
                        }//END-DO-S-loop  sections 1 to NSCT
                        //---------------------------------------

                        //draw the histogram of section increments
                        //and while looping, take opportunity to
                        //load the taxon row in the increment array for all taxa
                        //this will rewrite any existing row entry
                        //and thus avoid adding multiple passes to same row total
                        for (K = 0; K < COMMOD9.NEVNT; K++)
                        {
                            //plot histogram for FAD_LAD pairs only
                            //NOT  MAX-MIN pairs; they do not appear in COEX order!!
                            if (COMMOD9.IROWS[I, 1] != 1) continue;

                            if (COMMOD9.IROWS[I, 1] == 1) INCRALL[COMMOD9.IROWS[I, 2], K] = (int)(INCR[K]);

                            //incrall stores only FAD-LAD paired events
                            //incrall 1 row per taxon, in coex order,
                            //hence (IROWS,3)

                            if (INCR[K] == 0) continue;

                            valx = COMMOD9.COMPLVL[K, J - COMMOD9.NSCT];
                            stepup = (COMMOD9.COMPLVL[Math.Min(COMMOD9.NEVNT - 1, K + 1), J - COMMOD9.NSCT] +
                                COMMOD9.COMPLVL[K, J - COMMOD9.NSCT]) / 2.00;
                            stepdn = (COMMOD9.COMPLVL[K, J - COMMOD9.NSCT] +
                                COMMOD9.COMPLVL[Math.Max(0, K - 1), J - COMMOD9.NSCT]) / 2.00;

                            int xpos = Math.Min((int)(COMMOD9.lft + ((stepup - btmx) * scalx)), (int)(COMMOD9.lft + ((stepdn - btmx) * scalx)));
                            int ypos = Math.Min((int)(COMMOD9.maxy - COMMOD9.btm - 1),
                                (int)((COMMOD9.maxy - COMMOD9.btm - 1) - (((COMMOD9.btm * 4) - 10) * INCR[K] / Helper.MAXVal(INCR))));

                            //scale histogram bar to number of counts in INCR()
                            //and to space between composite sections and composite range
                            g.FillRectangle(frm.MSG_BRUSH_CCCCFF, xpos, ypos,
                                Math.Abs((int)(COMMOD9.lft + ((stepup - btmx) * scalx)) - (int)(COMMOD9.lft + ((stepdn - btmx) * scalx))),
                                Math.Abs((int)(-(((COMMOD9.btm * 4) - 10) * INCR[K] / Helper.MAXVal(INCR)))));
                        }

                        g.DrawString("  DISTRIBUTION", frm.MSG_FONT_S, frm.MSG_BRUSH_3333FF,
                            6, (int)(COMMOD9.maxy - COMMOD9.btm - 30));

                        g.DrawString("  OF SUPPORT", frm.MSG_FONT_S, frm.MSG_BRUSH_3333FF,
                            6, (int)(COMMOD9.maxy - COMMOD9.btm - 15));

                        // ----------------------------------------
                        //do titles
                        Output.COMPLBL(J + 1, ref xtitle);
                        xtitle = xtitle.Trim() + ": composite range in black";

                        g.RotateTransform(horiz);
                        g.DrawString(xtitle, frm.MSG_FONT, frm.MSG_BRUSH,
                            (int)(COMMOD9.lft + (COMMOD9.maxx - COMMOD9.lft) / 2),
                            (int)(COMMOD9.maxy - COMMOD9.btm / 2));

                        if (M == 1)
                        {
                            g.DrawString("WAIT FOR SCAN CYCLE TO COMPLETE", frm.MSG_FONT, frm.MSG_BRUSH,
                            (int)(COMMOD9.lft),
                            (int)(COMMOD9.btm));
                        }

                        g.ResetTransform();

                    }

                }//End for M

                upsection = true;
                Helper.SetVal(INCR, 0);

            }
            catch
            { }
        }
Exemple #9
0
        public void RunItAndDraw(frmCONOP frm, Graphics g)
        {
            double DELTA;

            double U;
            int INNER, IRANK, JRANK, LAST, OUTER, NCTR, FIXM, NABRM;
            int I, L, X, NCT;

            //CPMS  Declarations for graphics:
            //CPMS  PCT  Percentage annealed
            //CPMS  INISCOR - extension penalty for initial solution
            //CPMS  BSTSCOR - best extension penalty to date
            //CPMS  SCORes do not include the smoothing factors
            //CPMS  I??SCOR - initial scores for scaling the screen plots

            int INISCOR, ISMSCOR, ISQSCOR, ISHSCOR, ITSSCOR, INGSCOR;
            int BSTSCOR, AUTSCOR;
            double PCT;
            int dummy, ulx, uly, lrx, lry, res, siz;
            string SCORE;

            int horiz, vert, div;
            bool rndf, stepf, aimf, redf, trjf, algf, rlxf, rngf, hilf, s45f, s67f, s89f;

            COMMOD COMMOD9 = COMMOD.Singleton();

            //CPMS************************************************
            //CPMS***PRELIMINARIES
            //CPMS	 next section executes only once in a run
            //CPMS------------------------------------------------

            div = 0;
            res = 0;

            int scl = 0;
            int top = 0;
            int btm = 50;
            int lft = 100;
            int rit = 0;

            //C     initialize things for Intel 11.1
            COMMOD9.UU = 0.0;
            U = 0.0;
            PCT = 0.0;
            DELTA = 0.0;
            INNER = 0;
            IRANK = 0;
            JRANK = 0;
            LAST = 0;
            OUTER = 0;
            NCTR = 0;
            FIXM = 0;
            NABRM = 0;
            I = 0;
            L = 0;
            X = 0;
            NCT = 0;

            //C   initialized for Intel 9.0
            horiz = 0;
            vert = -90;//900  in Fortran
            rndf = true;
            INISCOR = 0;
            ITSSCOR = 0;
            ISMSCOR = 0;
            ISQSCOR = 0;
            ISHSCOR = 0;
            INGSCOR = 0;
            AUTSCOR = 0;
            BSTSCOR = 0;

            if ((COMMOD9.AUTF == 0) && (COMMOD9.CONTF == 0))
            {
                COMMOD9.BSTPEN = 0.0;
                COMMOD9.BS2PEN = 0.0;
            }

            COMMOD9.TOOPEN = 0.0;
            COMMOD9.TO2PEN = 0.0;
            COMMOD9.TSPEN = 0.0;
            COMMOD9.SMPEN = 0.0;
            COMMOD9.SHPEN = 0.0;
            COMMOD9.CRTPEN = 0.0;
            COMMOD9.NEWRANK = 0;
            //c  NEWRANK is the rank to which the last (BIG|SML) mutation moved an event

            //CPMS  set the screen grabber corners
            ulx = 0;
            uly = 0;
            lrx = COMMOD9.maxx - 1;
            lry = COMMOD9.maxy - 1;

            //C--------------------------------
            //C     set loop-accelerator flags
            //C     step-solutions (outer loop):
            stepf = false;
            if ((COMMOD9.STEPSOL.Substring(0, 3) != "OFF") && (COMMOD9.STEPSOL.Substring(0, 3) != "off"))
            {
                stepf = true;
            }

            //C  aimed tempering (outer loop):

            aimf = false;
            if ((COMMOD9.SOLVEF == 3) && (COMMOD9.FIXF == 2)) aimf = true;

            //C  animated ranges:
            rngf = false;
            if ((COMMOD9.RUNGRF == 2) || (COMMOD9.RUNGRF == 5)) rngf = true;

            //C  penalty trajectory:
            trjf = false;
            if (((COMMOD9.RUNGRF == 2) || (COMMOD9.RUNGRF == 0)) && (COMMOD9.TRJGRF > 0)) trjf = true;

            //C  red temp curve (inner loop):
            redf = false;
            if (trjf)
            {
                if ((COMMOD9.RUNGRF != 0) && (COMMOD9.SOLVEF != 2) && (COMMOD9.SOLVEF != 4) &&
                   (COMMOD9.SOLVEF != 6) && (COMMOD9.SOLVEF != 8)) redf = true;
            }

            //C  greedy algorithm:
            algf = false;
            if ((COMMOD9.SOLVEF == 2) || (COMMOD9.SOLVEF == 4) || (COMMOD9.SOLVEF == 6) ||
               (COMMOD9.SOLVEF == 8)) algf = true;

            //C  relaxed fit update:
            rlxf = false;
            if ((COMMOD9.RUNGRF >= 4) || (COMMOD9.GRIDF == 1)) rlxf = true;
            //C  uphill moves in different color:
            hilf = false;
            if ((COMMOD9.SOLVEF != 2) && (COMMOD9.TRJGRF >= 3)) hilf = true;

            //C  SOLVEF 4 or 5 (squeeze):
            s45f = false;
            if ((COMMOD9.SOLVEF == 4) || (COMMOD9.SOLVEF == 5)) s45f = true;

            //C  SOLVEF 6 or 7 (shrink)
            s67f = false;
            if ((COMMOD9.SOLVEF == 6) || (COMMOD9.SOLVEF == 7)) s67f = true;
            //C     SOLVEF 8 or 9 (stack)
            s89f = false;
            if ((COMMOD9.SOLVEF == 8) || (COMMOD9.SOLVEF == 9)) s89f = true;

            //C--------------------------------
            //C     set the initial temperature
            NCTR = 0;
            COMMOD9.CTRF = 0;
            COMMOD9.NBETR = 0;

            if (COMMOD9.CONTF == 1) goto Label111;

            switch (COMMOD9.AUTF)
            {
                case 0:
                    //cpms  not PAUSES='AUT','ADA'
                    COMMOD9.T = COMMOD9.STARTT;
                    break;
                case 1:
                    //cpms  still improving in last TRIALS - don't cool
                    //COMMOD9.T=COMMOD9.T;
                    COMMOD9.Rx = COMMOD9.R;
                    break;
                case -1:
                    //cpms   nothing better found in last TRIALS - cool
                    //c         The following line cools by a fixed amount
                    //c	        T = T*R
                    //c         In the alternative the size of the
                    //c         cooling step increases as the
                    //c         size of the null sets increases
                    //c         for adaprive cooling
                    COMMOD9.Rx = COMMOD9.R;
                    if ((COMMOD9.ADAF == 1) && (COMMOD9.NTRIES > 0) && (COMMOD9.LSTRIES > 1))
                    {
                        L = COMMOD9.RANDOM.Next(Math.Min(COMMOD9.LSTRIES, 5) + 1);//<=HXD
                        COMMOD9.Rx = Math.Pow(COMMOD9.R, L);
                        COMMOD9.NTRIES = COMMOD9.NTRIES + (L - 1);
                    }

                    COMMOD9.T = COMMOD9.T * COMMOD9.Rx;

                    break;
            }

            Label111:
            PCT = COMMOD9.NINNER * COMMOD9.NOUTER;

            //C--------------------------------------------------------
            //CPMS  alter OUTF so that GETPEN does not write to outmain
            //CPMS
            //**      OUTF = OUTF-100
            //CPMS
            //C     COMPUTE THE BEST PLACEMENTS THAT COMPLY WITH STARTING PERM
            //C       "INIPERM" AND RESULTING PENALTY.
            //C          PUT THE placements in SCTSOL and the PENALTY IN PEN
            //C
            //C     for the first permutation, we need a complete solution.
            //C         for subsequent perms, we may use reoptimization.
            //C---------------------------------------------------------
            if (COMMOD9.PENF <= 1)
            {
                Helper.GETPEN(COMMOD9.INIPERM, ref COMMOD9.NXTPEN);
            }
            else if (COMMOD9.PENF >= 2)
            {
                Helper.DEMPEN(COMMOD9.INIPERM, ref COMMOD9.NXTPEN);
            }

            //CPMS*********************************************
            //CPMS  PRELIMINARIES  -  not included in loops
            Helper.CopyArray(COMMOD9.INIPERM, ref COMMOD9.PERM);
            Helper.CopyArray(COMMOD9.INIPERM, ref COMMOD9.LSTPERM);
            Helper.CopyArray(COMMOD9.INIPERM, ref COMMOD9.PXLPERM);

            if (COMMOD9.CONTF == 0) Helper.CopyArray(COMMOD9.INIPERM, ref COMMOD9.BSTPERM);

            COMMOD9.PEN = COMMOD9.NXTPEN;
            COMMOD9.INIPEN = COMMOD9.NXTPEN;
            INISCOR = (int)COMMOD9.INIPEN;
            AUTSCOR = (int)COMMOD9.NXTPEN;

            if (COMMOD9.AUTF == 0)
            {
                if (COMMOD9.CONTF == 0) COMMOD9.BSTPEN = COMMOD9.NXTPEN;
            }
            else
            {
                if (COMMOD9.CONTF == 0) COMMOD9.BSTPEN = COMMOD9.AUTPEN;
            }

            BSTSCOR = (int)COMMOD9.BSTPEN;

            //Helper.DOTOO();

            COMMOD9.NGTPEN = COMMOD9.NGHPEN;
            INGSCOR = (int)COMMOD9.NGTPEN;

            if ((COMMOD9.AUTF == 0) && (COMMOD9.CONTF == 0))
            {
                COMMOD9.BS2PEN = COMMOD9.TOOPEN;
                COMMOD9.SQBST = COMMOD9.SQPEN;
                COMMOD9.SHBST = COMMOD9.SHPEN;
                COMMOD9.TSBST = COMMOD9.TSPEN;
            }

            ISQSCOR = (int)COMMOD9.SQPEN;
            ISHSCOR = (int)COMMOD9.SHPEN;
            COMMOD9.TSLST = COMMOD9.TSPEN;
            ITSSCOR = (int)COMMOD9.TSPEN;

            ISMSCOR = (int)COMMOD9.SMPEN;

            if ((COMMOD9.KSM > 0.0) && (COMMOD9.PENF < 2))
            {
                ISMSCOR = (int)(COMMOD9.SMPEN / COMMOD9.KSM);
                INISCOR = (int)(COMMOD9.PEN - COMMOD9.SMPEN);
                BSTSCOR = (int)(COMMOD9.BSTPEN - COMMOD9.SMPEN);
            }

            if (COMMOD9.CTRF == 1)
            {
                NCT = NCT + 1;
                COMMOD9.CTRF = 0;
            }

            if (COMMOD9.GRID2F == 1)
            {
                //cpms	 make sure that the .gr2 file records initial permutation

                for (X = 0; X < COMMOD9.NEVNT; X++)
                {
                    //cpms  update secondary penalty
                    COMMOD9.SECNDBST[COMMOD9.PERM[X], X] =
                        Math.Min(COMMOD9.SECNDBST[COMMOD9.PERM[X], X], COMMOD9.TO2PEN);
                }
            }

            //C-----------------------------------------------------------------------
            //C     to speed up reoptimization (in EVALUATE), keep track of
            //C         the last action taken during annealing.
            //C     if the new PERM was accepted,
            //C         SCTSOL and HSCTSOL will already be the same, and there is no need
            //C         to copy SCTSOL to HSCTSOL before reoptimization.
            //C     if the new permutation is not accepted, copy SCTSOL to HSCTSOL
            //C     use the flag LAST:
            //C        LAST = 1, accepted the new PERM
            //C        LAST = 0, did not accept the new PERM
            //C     since GETPEN calculates HSCTSOL, and we assign that to SCTSOL,
            //C         initialize it to 1.
            //C-----------------------------------------------------------------------
            //C     put the initial perm in PERM, the initial penalty in PEN, and
            //C     USE PERM AND PEN AS THE INITIAL "BEST" VALUES
            //C-----------------------------------------------------------------------

            Helper.CopyArray(COMMOD9.HSCTSOL, ref COMMOD9.SCTSOL);
            Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);
            LAST = 1;
            COMMOD9.XPOSN = 0;

            if (COMMOD9.FIXF == 3)
            {
                for (COMMOD9.XPOSN = 0; COMMOD9.XPOSN < COMMOD9.NEVNT; COMMOD9.XPOSN++)
                {
                    if (COMMOD9.PERM[COMMOD9.XPOSN] == COMMOD9.XEVNT) break;
                }
            }

            //HACK:OMIT MANY LINES
            //CPMS  --if plotting during run-----------------
            if (rngf)
            {
                if (COMMOD9.CONTF == 1)
                {
                    DRAWCHT(frm, g, 1, COMMOD9.INIPERM);
                }
                else
                {
                    DRAWCHT(frm, g, 1, COMMOD9.BSTPERM);
                }
            }
            else if (COMMOD9.RUNGRF == 4)
            {
                if (COMMOD9.CONTF == 1)
                {
                    DRAWCHT(frm, g, 3, COMMOD9.INIPERM);
                }
                else
                {
                    DRAWCHT(frm, g, 3, COMMOD9.BSTPERM);
                }
            }
            else if (COMMOD9.MOVEF == 1)
            {
                //CALL EDITDIVE(0) ????
            }

            if (((COMMOD9.RUNGRF == 2) || (COMMOD9.RUNGRF >= 4)) && (COMMOD9.TRJGRF > 0))
            {
                //---if filling curves, decrease INISCOR to enlarge lower half of curve
                if ((COMMOD9.RUNGRF == 4) && (COMMOD9.INIGEN != 2)) INISCOR = (int)(INISCOR / 2);

                //---if tracking secondary penalties
                //---scale them to half screen height
                switch (COMMOD9.SOLVEF)
                {
                    case 4:
                    case 5:
                        if (COMMOD9.INIGEN != 2) ISQSCOR = ISQSCOR * 2;
                        break;
                    case 6:
                    case 7:
                        if (COMMOD9.INIGEN != 2) ISHSCOR = ISHSCOR * 2;
                        break;
                    case 8:
                    case 9:
                        if (COMMOD9.INIGEN != 2) ITSSCOR = ITSSCOR * 2;
                        break;
                }

                if (COMMOD9.NEGATF > 0) INGSCOR = INGSCOR * 4;

                //CPMS   ---if starting from a previous solution on file--------------
                if (COMMOD9.INIGEN == 2)
                {
                    //starting from file gives a low initial penalty and the search
                    //frequently climbs higher; so the initial penalty is scaled to
                    //half the screen height!
                    INISCOR = INISCOR * 2;

                    //and the secondary penalty is scaled to 2/3 screen height
                    ISQSCOR = (int)((double)(ISQSCOR) * 1.3);
                    ISHSCOR = (int)((double)(ISHSCOR) * 1.3);
                    ITSSCOR = (int)((double)(ITSSCOR) * 1.3);

                    //and any negative penalty is scaled to 1/3 height
                    INGSCOR = (int)((double)(INGSCOR) * 3);

                    frm.SetColor(10);

                    if (COMMOD9.AUTF == 0) rndf = false;

                    YSCALE(frm, g, INISCOR, COMMOD9.maxx, COMMOD9.maxy, top, btm, lft - 1, res, rndf);

                    frm.SetColor(8);

                    SCORE = string.Format("{0}", INISCOR);
                    LBLSCOR(frm, g, SCORE, 0);

                    //label the initial penalty
                    if (COMMOD9.AUTF == 0) frm.SetColor(10);
                    SCORE = string.Format("{0}", AUTSCOR);
                    LBLSCOR(frm, g, SCORE, 1000 * (INISCOR - AUTSCOR) / INISCOR);

                    if (COMMOD9.AUTF != 0)
                    {
                        //label the best score (carried forward)
                        frm.SetColor(10);
                        SCORE = string.Format("{0}", BSTSCOR);
                        LBLSCOR(frm, g, SCORE, 1000 * (INISCOR - BSTSCOR) / INISCOR);
                    }
                }
                else//---else if starting from scratch------
                {
                    //make top of y-axis a round number
                    //with resolution "res"
                    res = 0;
                    frm.SetColor(10);
                    YSCALE(frm, g, INISCOR, COMMOD9.maxx, COMMOD9.maxy, top, btm, lft - 1, res, rndf);
                }

                //  plot the initial penalties:
                //  the next line had ninner twice: a mistake?
                if ((COMMOD9.NINNER > 0) && (COMMOD9.NOUTER > 0) && (rngf))
                {
                    DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(INISCOR), (double)(BSTSCOR), 2, 1);

                    if (COMMOD9.NEGATF > 0)
                    {
                        //plot negative penalty in brown
                        frm.SetColor(6);
                        DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(INGSCOR), (double)(COMMOD9.NGHPEN), 0, 1);
                    }

                    //plot secondary penalties in dark blue
                    frm.SetColor(1);

                    switch (COMMOD9.SOLVEF)
                    {
                        case 1:
                        case 2:
                        case 3:
                            break;
                        case 4:
                        case 5:
                            DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(ISQSCOR), (double)(COMMOD9.SQPEN), 2, 1);
                            break;
                        case 6:
                        case 7:
                            DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(ISHSCOR), (double)(COMMOD9.SHPEN), 2, 1);
                            break;
                        case 8:
                        case 9:
                            DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(ITSSCOR), (double)(COMMOD9.TSPEN), 2, 1);
                            break;
                    }

                    frm.SetColor(15);
                }
                else if ((COMMOD9.NINNER > 0) && rlxf) //ELSE IF((NINNER.GT.0.).AND.(NINNER.GT.0.).AND.rlxf) THEN   <=HXD??
                {
                    FILLBEST(frm, g, INISCOR, (double)BSTSCOR);
                }
                else
                {
                    frm.SetColor(15);
                    return;//???<=HXD
                }
            }

            if (COMMOD9.RUNGRF == 4)
            {
                //plot the xevnt position
                frm.SetColor(8);
                for (I = 0; I < COMMOD9.NEVNT; I++)
                {
                    if (INISCOR > (int)(COMMOD9.EVERYBST[COMMOD9.XEVNT, I]))
                    {
                        DRAWSCOR(frm, g, (double)COMMOD9.NEVNT, (double)(COMMOD9.NEVNT - (I + 1)),
                            (double)(INISCOR), COMMOD9.EVERYBST[COMMOD9.XEVNT, I], 1, 1);
                    }
                }

                frm.SetColor(0);
            }

            //cpms---reset CONTF after first pass through--------------

            COMMOD9.CONTF = 0;

            //CPMS*******************************************************************
            //CPMS  MAIN LOOPS
            //C     The following lines are executed with every trial!!
            //C     Analyse a big sequence of neighbors ('permutations').
            //C     Compute the penalty and decide whether to accept the new perm
            //C     according to the SOLVER option
            //C-------------------------------------------------------------
            //CPMS---Store two run parameters in case the last temper quench is
            //CPMS   to be "aimed" into the optimum with different parameters
            //CPMS   and the program must reset for another "RPT" run.
            FIXM = COMMOD9.FIXF;
            NABRM = COMMOD9.NABRGEN;

            //Helper.Write("\n  ");
            //if (COMMOD9.PAUSF != 5)
            //{
            //    Console.BackgroundColor = ConsoleColor.Blue;
            //}

            //CPMS**START THE OUTER LOOP***************
            for (OUTER = 0; OUTER < (int)COMMOD9.NOUTER; OUTER++)
            {

                //CPMS	check for "AIM"ed tempering
                if ((aimf) && (OUTER == (int)COMMOD9.NOUTER - 1))
                {
                    COMMOD9.FIXF = 0;
                    COMMOD9.NABRGEN = 2;
                }

                //CPMS  write out best solution so far if requested
                if ((stepf) && (COMMOD9.CDF != 1)) Helper.STEPOUT(COMMOD9.BSTPERM);
                if ((stepf) && (COMMOD9.CDF != 1)) Helper.TRAJOUT();

                //CPMS*****START THE INNER LOOP*********
                for (INNER = 0; INNER < (int)COMMOD9.NINNER; INNER++)
                {

                    PCT = PCT - 1;

                    //Draw the red temperature trajectory on the screen
                    //if not "greedy" or "squeeze" or "shrink" or "tease"
                    if (redf)
                    {
                        frm.SetColor("BB0000");
                        DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, COMMOD9.STARTT, COMMOD9.T, 0, 1);
                        frm.SetColor(15);
                    }

                    //CPMS-----------------------------------------------------
                    //CPMS       GENERATE A NEIGHBOR AS A CANDIDATE PERMUTATION
                    //CPMS       after saving current state of secondary penalty
                    COMMOD9.TSLST = COMMOD9.TSPEN;

                    Helper.GONABR(ref IRANK, ref JRANK);

                    //CPMS******    This replaces the old calculation of PROB after penalty totalling
                    //CPMS******    It allows NEWPEN to exit the section loop as soon as the critical
                    //CPMS******    penalty size (CRTPEN) is reached.
                    //CPMS******    NEWPEN takes advantage of this, but NWDMPEN does not.....yet
                    //CPMS******    for a riley test, running time drops from 1.133 to 1.117 mins.
                    COMMOD9.UU = COMMOD9.RANDOM.NextDouble();

                    //if(COMMOD9.PEN>4000 && COMMOD9.PEN<5000)
                    //    Helper.Write(" T={0} UU={1} Pen={2} ", COMMOD9.T,COMMOD9.UU,COMMOD9.PEN);
                    COMMOD9.CRTPEN = COMMOD9.PEN - (COMMOD9.T * Math.Log(COMMOD9.UU));
                    //if (COMMOD9.PEN > 4000 && COMMOD9.PEN < 5000)
                    //    Helper.Write("CRTPEN={0}\n", COMMOD9.CRTPEN);

                    if (COMMOD9.PENF <= 1)
                    {
                        Helper.NEWPEN(IRANK, JRANK, COMMOD9.PERM, ref COMMOD9.NXTPEN);

                    }
                    else if (COMMOD9.PENF >= 2)
                    {
                        Helper.NWDMPEN(IRANK, JRANK, COMMOD9.PERM, ref COMMOD9.NXTPEN);
                    }

                    DELTA = COMMOD9.NXTPEN - COMMOD9.PEN;

                    //C-----------------------------------------------------------------------
                    //C    DETERMINE WHETHER TO ACCEPT THE NEW PERM OR KEEP THE
                    //C    OLD ONE
                    //C    PEN is the previous penalty
                    //C    NXTPEN is the candidate to replace PEN
                    //C    DELTA is the difference
                    //C-----------------------------------------------------------------------

                    //C-----------------------------------------------------------------------
                    //c          set the flag LAST to 0, saying that the new PERM
                    //C          has not been accepted yet
                    //C
                    //C          IF THE NEW PERM IS BETTER (OR AS GOOD and not "GREEDY"),
                    //C            1. ACCEPT IT, keep PERM, update PEN, TOOPEN and SCTSOL, AND
                    //C            2. SEE IF IT IS BEST SO FAR
                    //C             IF IT IS, UPDATE THE BEST SO FAR (BSTPERM AND BSTPEN)
                    //C		      If a "SQUEEZE" run, accept only if squeeze penalty is not worse
                    //C-----------------------------------------------------------------------

                    LAST = 0;

                    //CPMS       ? replace the next IF with DELTA.LE.0
                    //CPMS       i.e. always accept an equally good move and save the checking time
                    //CPMS       ?? leads to lots of repetitions
                    //CPMS       ??? what is the snag for greedy?
                    //c          /////////////////////////////////////////
                    //CPMS       IF NEW SEQUENCE HAS SAME OR LOWER PENALTY
                    if ((DELTA < 0.0) ||
                        ((DELTA == 0.0) && ((COMMOD9.SOLVEF < 2) ||
                        ((s89f) && (COMMOD9.TSPEN <= COMMOD9.TSBST)) ||
                        ((s67f) && (COMMOD9.SHPEN <= COMMOD9.SHBST)) ||
                        ((s45f) && (COMMOD9.SQPEN <= COMMOD9.SQBST)))))
                    {
                        if (COMMOD9.MOVEF == 1)
                        {
                            //CALL EDITDIVE(1) ************************
                        }

                        if (COMMOD9.NEGATF > 0)
                        {
                            frm.SetColor(6);
                            DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(INGSCOR), (double)(COMMOD9.NGHPEN), 0, 1);
                            frm.SetColor(15);
                        }

                        frm.SetColor(1);
                        switch (COMMOD9.SOLVEF)
                        {
                            case 4:
                            case 5:
                                //plot sqpen in dark blue, if sqpen is unchanged
                                //primary penalty is not worse
                                DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(ISQSCOR), (double)(COMMOD9.SQPEN), 0, 1);
                                break;
                            case 6:
                            case 7:
                                //plot shpen in dark blue, if shpen is unchanged
                                //primary penalty is not worse
                                DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(ISHSCOR), (double)(COMMOD9.SHPEN), 0, 1);
                                break;
                            case 8:
                            case 9:
                                //plot tspen in dark blue, if tspen is unchanged
                                //primary penalty is not worse
                                DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(ITSSCOR), (double)(COMMOD9.TSPEN), 0, 1);
                                break;
                        }

                        frm.SetColor(15);

                        if (COMMOD9.CTRF == 1)
                        {
                            NCT = NCT + 1;
                            COMMOD9.CTRF = 0;
                        }

                        //update the penalties
                        COMMOD9.PEN = COMMOD9.NXTPEN;
                        COMMOD9.ASPNPEN = COMMOD9.SPANPEN;

                        Helper.DOTOO();

                        if (COMMOD9.PENF < 2)
                        {
                            Helper.CopyArray(COMMOD9.HSCTSOL, ref COMMOD9.SCTSOL);
                        }

                        Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                        LAST = 1;

                        //if this is very best so far
                        if ((COMMOD9.PEN < COMMOD9.BSTPEN) || ((COMMOD9.PEN == COMMOD9.BSTPEN) &&
                            (((s89f) && (COMMOD9.TSPEN < COMMOD9.TSBST)) ||
                            ((s67f) && (COMMOD9.SHPEN < COMMOD9.SHBST)) ||
                            ((s45f) && (COMMOD9.SQPEN < COMMOD9.SQBST)))))
                        {
                            siz = 2;
                            if (COMMOD9.PEN == COMMOD9.BSTPEN) siz = 1;

                            if (COMMOD9.NEGATF > 0)
                            {
                                frm.SetColor(6);
                                DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(INGSCOR), (double)(COMMOD9.NGHPEN), 0, 1);
                                frm.SetColor(15);
                            }

                            //change color for secondary penalty
                            frm.SetColor(9);
                            switch (COMMOD9.SOLVEF)
                            {
                                case 4:
                                case 5:
                                    if ((COMMOD9.SQPEN < COMMOD9.SQBST) || (COMMOD9.PEN < COMMOD9.BSTPEN))
                                    {
                                        DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(ISQSCOR), (double)(COMMOD9.SQPEN), 1, 1);
                                    }
                                    break;
                                case 6:
                                case 7:
                                    if ((COMMOD9.SHPEN < COMMOD9.SHBST) || (COMMOD9.PEN < COMMOD9.BSTPEN))
                                    {
                                        DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(ISHSCOR), (double)(COMMOD9.SHPEN), 1, 1);
                                    }
                                    break;
                                case 8:
                                case 9:
                                    if ((COMMOD9.TSPEN < COMMOD9.TSBST) || (COMMOD9.PEN < COMMOD9.BSTPEN))
                                    {
                                        DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(ITSSCOR), (double)(COMMOD9.TSPEN), 1, 1);
                                    }
                                    break;
                            }

                            frm.SetColor(15);

                            COMMOD9.SQBST = COMMOD9.SQPEN;
                            COMMOD9.SHBST = COMMOD9.SHPEN;
                            COMMOD9.TSBST = COMMOD9.TSPEN;
                            COMMOD9.BSTPEN = COMMOD9.PEN;
                            COMMOD9.NBETR = COMMOD9.NBETR + 1;
                            COMMOD9.BS2PEN = COMMOD9.TOOPEN;
                            COMMOD9.NGTPEN = COMMOD9.NGHPEN;
                            BSTSCOR = (int)COMMOD9.BSTPEN;

                            if ((COMMOD9.KSM > 0.00) && (COMMOD9.PENF < 2)) BSTSCOR = BSTSCOR - (int)COMMOD9.SMPEN;

                            Helper.CopyArray(COMMOD9.PERM, ref COMMOD9.BSTPERM);

                            if (trjf)
                            {
                                //update trajectory on range graph
                                frm.SetColor(10);
                                DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)INISCOR, (double)BSTSCOR, siz, 1);

                                frm.SetColor(15);
                                //if smoothing, show smoothing penalty term too
                                if ((COMMOD9.KSM > 0.00) && (COMMOD9.PENF < 2))
                                {
                                    BSTSCOR = (int)(COMMOD9.SMPEN / COMMOD9.KSM);
                                    frm.SetColor(2);
                                    DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)ISMSCOR, (double)BSTSCOR, 0, 1);

                                    BSTSCOR = (int)(COMMOD9.BSTPEN - COMMOD9.SMPEN);
                                    frm.SetColor(15);
                                }
                            }
                        }

                        // END OF penalty updates for acceptance
                        // Now edit the range lines because switch was accepted
                        if (rngf)
                        {
                            EDITCHT(frm, g, IRANK, JRANK);
                            //plot uphill moves in contrasting color!!
                            if (hilf)
                            {
                                //update trajectory on range graph
                                frm.SetColor(8);
                                DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT, (double)(INISCOR), COMMOD9.PEN, 1, 1);
                                frm.SetColor(15);
                            }
                        }

                        // END OF ACCEPTANCE ROUTINES
                        // update the relaxed fit curves
                        if (rlxf)
                        {
                            FILLBEST(frm, g, INISCOR, COMMOD9.PEN);
                        }

                    }
                    else
                    {
                        //C-----------------------------------------------------------------------
                        //C    LOOK FOR PROBABILISTIC GROUNDS TO ACCEPT
                        //C    EVEN IF THE NEW PERM IS WORSE THAN "PERM",
                        //C    ACCEPT IT WITH PROBABILITY "PROB"
                        //C    PROB replaced by CRTPEN - the critical penalty at PROB
                        //C  //////////////////////////////////////////////////////////////

                        //NOT AN IMPROVEMENT
                        if (COMMOD9.NUDGER)
                        {
                            COMMOD9.NUDGUP = false;
                            COMMOD9.NUDGDN = false;
                        }

                        //CPMS   reject and reset for greedy algorithm
                        //cpms   and shrinker and squeezer and teaser
                        if (algf)
                        {
                            Helper.CopyArray(COMMOD9.LSTPERM, ref COMMOD9.PERM);

                            COMMOD9.TSPEN = COMMOD9.TSLST;

                            if (trjf)
                            {
                                //update trajectory on range graph
                                frm.SetColor(8);
                                DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT,
                                    (double)INISCOR, (double)(BSTSCOR), 0, 1);
                                frm.SetColor(15);
                            }

                        }
                        else
                        {
                            //cpms-----------for squeal and anneas and steal--------
                            //cpms	  adjust U downward if 2nd penalty improves
                            //cpms    and up if the 2nd penalty worsens
                            //cpms    adjust according to the new/old ratio squared
                            //cpms	   the adjustments are likely to be small
                            //cpms    but they increase geometrically as the
                            //cpms    impact on the secondary penalty increases
                            //cpms
                            //cpms    the efficiency of the promary search is compromised
                            //cpms    but the secondary penalty is not allowed to
                            //cpms    increase uncontrollably

                            switch (COMMOD9.SOLVEF)
                            {
                                case 1:
                                case 2:
                                case 3:
                                case 4:
                                case 6:
                                case 8:
                                    break;
                                case 5:
                                    if (COMMOD9.SQPEN > 0)
                                        U = U * Math.Pow((COMMOD9.SQPEN / COMMOD9.SQBST), 2);
                                    break;
                                case 7:
                                    if (COMMOD9.SHPEN > 0)
                                        U = U * Math.Pow((COMMOD9.SHPEN / COMMOD9.SHBST), 2);
                                    break;
                                case 9:
                                    if (COMMOD9.TSPEN > 0)
                                        U = U * Math.Pow((COMMOD9.TSPEN / COMMOD9.TSBST), 2);
                                    break;
                            }

                            //cpms-------------------------------------------------

                            if (COMMOD9.NXTPEN < COMMOD9.CRTPEN)
                            {
                                //CPMS    ACCEPT UPHILL STEP
                                //CPMS    and check contraction
                                if (COMMOD9.CTRF == 1)
                                {
                                    NCT = NCT + 1;
                                    COMMOD9.CTRF = 0;
                                }

                                if (COMMOD9.NEGATF > 0)
                                {
                                    frm.SetColor(6);
                                    DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT,
                                        (double)INGSCOR, (double)COMMOD9.NGHPEN, 0, 1);
                                    frm.SetColor(15);
                                }

                                frm.SetColor(9);

                                switch (COMMOD9.SOLVEF)
                                {
                                    case 1:
                                    case 2:
                                    case 3:
                                    case 4:
                                    case 6:
                                    case 8:
                                        break;
                                    case 5:
                                        COMMOD9.SQBST = COMMOD9.SQPEN;
                                        DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT,
                                        (double)ISQSCOR, (double)COMMOD9.SQPEN, 0, 1);
                                        break;
                                    case 7:
                                        COMMOD9.SHBST = COMMOD9.SHPEN;
                                        DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT,
                                        (double)ISHSCOR, (double)COMMOD9.SHPEN, 0, 1);
                                        break;
                                    case 9:
                                        COMMOD9.TSBST = COMMOD9.TSPEN;
                                        DRAWSCOR(frm, g, COMMOD9.NOUTER * COMMOD9.NINNER, PCT,
                                        (double)ITSSCOR, (double)COMMOD9.TSPEN, 0, 1);
                                        break;
                                }

                                frm.SetColor(15);

                                //update total penalty and secondary penalty
                                COMMOD9.PEN = COMMOD9.NXTPEN;
                                COMMOD9.ASPNPEN = COMMOD9.SPANPEN;

                                Helper.DOTOO();

                                if (COMMOD9.PENF < 2)
                                {
                                    Helper.CopyArray(COMMOD9.HSCTSOL, ref COMMOD9.SCTSOL);
                                }

                                Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                                LAST = 1;

                                //Edit the range lines because bad switch is accepted
                                if (rngf)
                                {
                                    EDITCHT(frm, g, IRANK, JRANK);
                                }

                                //CPMS	 Load the EVERYBST array and add points to
                                //CPMS	 the event bathtub - needs to be a separate subroutine
                                if (rlxf)
                                {
                                    FILLBEST(frm, g, INISCOR, COMMOD9.PEN);
                                    //run through the solution in sequence (EVERYBST cols)
                                    //and enter the penalty for the appropriate
                                    //event (EVERYBST rows), IF the best so far
                                    //i.e. EVERYBST has IROWS order
                                }

                            }
                            else
                            {
                                //C-----------------------------------------------------------------------
                                //CPMS     REJECT UPHILL STEP reset PERM to previous order (any NABRGEN!)
                                //CPMS	   no boxes plotted on the run-time graphic
                                //CPMS     no update to PEN or TOOPEN
                                //CPMS--------------------------------------------------------
                                Helper.CopyArray(COMMOD9.LSTPERM, ref COMMOD9.PERM);
                                COMMOD9.TSPEN = COMMOD9.TSLST;
                                COMMOD9.CTRF = 0;
                            }
                        }
                    }//END if ELSE DELTA>0

                    //cpms  if tempering:
                    if (COMMOD9.SOLVEF == 3) COMMOD9.T = COMMOD9.T * COMMOD9.R;

                    System.Windows.Forms.Application.DoEvents();
                    System.Threading.Thread.Sleep(0);

                }//CPMS*****end of inner loop**************

                //C  lower the temperature and do it again if annealing
                //C  heat to random temperature and quench again if tempering (solvef=3)

                if (COMMOD9.SOLVEF == 3)
                {
                    U = COMMOD9.RANDOM.NextDouble();

                    //c	 PCT/NINNER*NOUTER runs from 1.0 to 0.0
                    //c      IF random number is larger, try again
                    //c      reduces frequency of hot tempers later in run
                    COMMOD9.T = COMMOD9.STARTT * PCT / (COMMOD9.NINNER * COMMOD9.NOUTER) * U;

                    if (COMMOD9.PENF < 2)
                    {
                        Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.PEN);
                    }
                    else if ((COMMOD9.PENF == 5) || (COMMOD9.PENF == 6))
                    {
                        Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.PEN);
                    }
                    else if (COMMOD9.PENF > 1)
                    {
                        Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.PEN);
                    }

                    Helper.CopyArray(COMMOD9.BSTPERM, ref COMMOD9.PERM);
                    Helper.CopyArray(COMMOD9.HSCTSOL, ref COMMOD9.SCTSOL);
                    Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                    //refresh the range lines
                    if (rngf) DRAWCHT(frm, g, 2, COMMOD9.BSTPERM);
                }
                else
                {
                    if (COMMOD9.AUTF == 0) COMMOD9.T = COMMOD9.T * COMMOD9.R;

                    if ((COMMOD9.AUTF == 0) && (COMMOD9.CDF != 1)) Helper.TRAJOUT();
                }

            }//cpms**end of outer loop*********************************************

            COMMOD9.AUTPEN = COMMOD9.BSTPEN;
            COMMOD9.NUDGUP = false;
            COMMOD9.NUDGDN = false;

            //CPMS  Now turn to tasks completed only once per run, AFTER annealing
            //cpms-----------------
            //CPMS	restore FIXF and NABRGEN
            COMMOD9.FIXF = FIXM;
            COMMOD9.NABRGEN = NABRM;

            //CPMS-----------------------------------------------------------
            //CPMS     write out last solution tried if requested
            if ((COMMOD9.STEPSOL.Substring(0, 3) == "LST") ||
                (COMMOD9.STEPSOL.Substring(0, 3) == "lst"))
            {
                if (COMMOD9.CDF != 1) Helper.STEPOUT(COMMOD9.LSTPERM);

                if (COMMOD9.CDF != 1) Helper.TRAJOUT();

            }
            //C--------------------------------------------------------------
            //C     save value of PENF
            LAST = COMMOD9.PENF;

            //CPMS  Try to prevent the remaining tasks from
            //c     running during auto-cooling until about to stop
            if ((COMMOD9.PAUSF == 5) && (COMMOD9.NTRIES < COMMOD9.NSTOP - 1))
            {
                COMMOD9.NUDGUP = false;
                COMMOD9.NUDGDN = false;

                goto Label33;
            }

            //C     after all NOUTER*NINNER passes through the loop,
            //CPMS  make sure that HSCTSOL reflects the best solution
            //CPMS  rather than the last tried
            //CPMS  and that HSCTSOL is last set according to correct penalty
            //CPMS  i.e. lvlpen if PENF=1, intpen for all other cases

            if (COMMOD9.PENF == 1)
            {
                COMMOD9.PENF = -1;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.RVLPEN);
                if (LAST == -1) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                COMMOD9.PENF = 0;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.INTPEN);
                if (LAST == 0) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                COMMOD9.PENF = 1;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.LVLPEN);
                if (LAST == 1) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);
            }
            else if (COMMOD9.PENF == 0)
            {
                COMMOD9.PENF = -1;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.RVLPEN);
                if (LAST == -1) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                COMMOD9.PENF = 1;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.LVLPEN);
                if (LAST == 1) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                COMMOD9.PENF = 0;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.INTPEN);
                if (LAST == 0) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);
            }
            else if (COMMOD9.PENF == -1)
            {
                COMMOD9.PENF = 1;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.LVLPEN);
                if (LAST == 1) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                COMMOD9.PENF = 0;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.INTPEN);
                if (LAST == 0) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                COMMOD9.PENF = -1;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.RVLPEN);
                if (LAST == -1) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

            }

            COMMOD9.NGTPEN = COMMOD9.NGHPEN;
            //CPMS  GETPEN places local horizons to fit the best sequence
            //CPMS  but the final penalty needs to be returned to its
            //CPMS  "democratic" value for an ordinal search

            COMMOD9.PENF = 6;
            if (COMMOD9.FB4LF != 0) Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.SEQPEN);

            COMMOD9.PENF = 5;
            Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.ROYPEN);

            COMMOD9.PENF = 7;
            Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.MOMPEN);
            if (LAST == 7) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

            COMMOD9.PENF = 4;
            Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.RSCPEN);
            if (LAST == 4) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

            COMMOD9.PENF = 3;
            Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.SPTPEN);
            if (LAST == 3) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

            COMMOD9.PENF = 2;
            Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.ORDPEN);
            if (LAST == 2) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);
            if (LAST == 5) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);
            if ((LAST == 6) && (COMMOD9.FB4LF != 0)) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

            //C   SCJPEN now contains the primary section penalties
            //C   But this is pointless for Royal (PENF=5)
            //C   and for Sequel (PENF=6) so
            //C   the ordinal penalty is used instead

            if (LAST > 2)
            {
                COMMOD9.PENF = 0;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.INTPEN);

                //C   COLPEN now contains the ordinal or interval penalties
                //C   whichever contrasts with the primary
            }

            //c  restore PENF
            COMMOD9.PENF = LAST;
            switch (COMMOD9.PENF)
            {
                case -1://eventual
                    COMMOD9.BSTPEN = COMMOD9.RVLPEN;
                    break;
                case 0://interval
                    COMMOD9.BSTPEN = COMMOD9.INTPEN;
                    break;
                case 1://level
                    COMMOD9.BSTPEN = COMMOD9.LVLPEN;
                    break;
                case 2://ordinal
                    COMMOD9.BSTPEN = COMMOD9.ORDPEN;
                    break;
                case 3://spatial
                    COMMOD9.BSTPEN = COMMOD9.SPTPEN;
                    break;
                case 4://rascal/rascer
                    COMMOD9.BSTPEN = COMMOD9.RSCPEN;
                    break;
                case 5://royal (Coex)
                    COMMOD9.BSTPEN = COMMOD9.ROYPEN;
                    break;
                case 6://sequel (Fb4L)
                    if (COMMOD9.FB4LF != 0) COMMOD9.BSTPEN = COMMOD9.SEQPEN;
                    break;
                case 7://momental
                    COMMOD9.BSTPEN = COMMOD9.MOMPEN;
                    break;
            }

            Label33:

            if (((COMMOD9.RUNGRF == 2) || (COMMOD9.RUNGRF >= 4)) && (COMMOD9.TRJGRF > 0))
            {
                frm.SetColor(10);
                BSTSCOR = (int)COMMOD9.BSTPEN;
                SCORE = string.Format("{0}", BSTSCOR);
                LBLSCOR(frm, g, SCORE, 1000 * (INISCOR - BSTSCOR) / INISCOR);
                frm.SetColor(15);
            }

            //CPMS-------------------------------------------------------------
            //CPMS  transfer the number of contractions to a common variable
            COMMOD9.CTRF = NCTR;
        }
Exemple #10
0
        private void RANGEBARINC(frmCONOP frm, Graphics g, Pen pen, double v1x, double v2x, int Jx, int Jy, double btx, double sclx, int flg, bool bsf, bool tpf)
        {
            //Jx = section number; Jy = section total
            //flg=0: local range
            //flg=1: composite range (thicker line; grey limit bars)
            //bsf, tpf = flags for ranges to base and top of section

            pen.Width = 2;
            COMMOD COMMOD9 = COMMOD.Singleton();

            //draw range
            if (((bsf) || (tpf)) && (flg == 0)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; }//CALL  SETLINESTYLE(INT2(#8888))

            int xpos = Math.Min((int)(COMMOD9.lft + ((v1x - btx) * sclx) - 1), (int)(COMMOD9.lft + ((v2x - btx) * sclx) - 1));
            int ypos = Math.Min((int)(COMMOD9.top + Jx * (COMMOD9.maxy - COMMOD9.top - (COMMOD9.btm * 5)) / (double)(Jy + 2)),
                (int)(flg + COMMOD9.top + Jx * (COMMOD9.maxy - COMMOD9.top - (COMMOD9.btm * 5)) / (double)(Jy + 2)));

            if (flg == 0)
            {
                g.DrawLine(pen, (int)(COMMOD9.lft + ((v1x - btx) * sclx) - 1),
                (int)(COMMOD9.top + Jx * (COMMOD9.maxy - COMMOD9.top - (COMMOD9.btm * 5)) / (double)(Jy + 2)),
                (int)(COMMOD9.lft + ((v2x - btx) * sclx) - 1),
                (int)(flg + COMMOD9.top + Jx * (COMMOD9.maxy - COMMOD9.top - (COMMOD9.btm * 5)) / (double)(Jy + 2)));
            }
            else
            {

                g.DrawRectangle(pen, xpos, ypos,
                    Math.Abs((int)((v2x - v1x) * sclx + 2)), Math.Abs((int)(flg)));
            }

            //CALL SETLINESTYLE(INT2(#FFFF))
            pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;

            //draw range ends (if within section)
            if (bsf == false)
            {

                g.DrawRectangle(pen, (int)(COMMOD9.lft + ((v1x - btx) * sclx) - 1),
                    (int)(COMMOD9.top - 1 + Jx * (COMMOD9.maxy - COMMOD9.top - (COMMOD9.btm * 5)) / (double)(Jy + 2)),
                    2, Math.Abs((int)(flg + 2)));
            }

            if (tpf == false)
            {
                g.DrawRectangle(pen, (int)(COMMOD9.lft + ((v2x - btx) * sclx) - 1),
                   (int)(COMMOD9.top - 1 + Jx * (COMMOD9.maxy - COMMOD9.top - (COMMOD9.btm * 5)) / (double)(Jy + 2)),
                   2, Math.Abs((int)(flg + 2)));
            }

            pen.Width = 1;

            //draw vertical grey bars at composite range limit
            if (flg == 1)
            {
                //g.DrawRectangle(frm.DRAW_PEN_7, (int)(COMMOD9.lft + ((v1x - btx) * sclx) - 1),
                //    (int)(COMMOD9.top),
                //    0, Math.Abs((int)(10 + Jx * (COMMOD9.maxy - COMMOD9.top - (COMMOD9.btm * 5)) / (double)(Jy + 2))));

                g.DrawLine(frm.DRAW_PEN_7, (int)(COMMOD9.lft + ((v1x - btx) * sclx) - 1), (int)(COMMOD9.top),
                    (int)(COMMOD9.lft + ((v1x - btx) * sclx) - 1),
                    (int)(10 + COMMOD9.top + Jx * (COMMOD9.maxy - COMMOD9.top - (COMMOD9.btm * 5)) / (double)(Jy + 2)));

                g.DrawLine(frm.DRAW_PEN_7, (int)(COMMOD9.lft + ((v2x - btx) * sclx) - 1), (int)(COMMOD9.top),
                    (int)(COMMOD9.lft + ((v2x - btx) * sclx) - 1),
                    (int)(10 + COMMOD9.top + Jx * (COMMOD9.maxy - COMMOD9.top - (COMMOD9.btm * 5)) / (double)(Jy + 2)));

            }
        }
Exemple #11
0
        public void DO1(frmCONOP frm, Graphics g)
        {
            COMMOD COMMOD9 = COMMOD.Singleton();

            g.DrawString("PROGRAM  WILL  FIRST  SCAN  RAPIDLY  THROUGH  ALL  TAXA.",
                frm.MSG_FONT, frm.MSG_BRUSH, (int)COMMOD9.lft, (int)COMMOD9.btm);

            g.DrawString("THEN PROMPT FOR RAREFACTION CALCULATIONS.",
                frm.MSG_FONT, frm.MSG_BRUSH, (int)COMMOD9.lft, (int)COMMOD9.btm + 25);

            g.DrawString("  After screen returns to first taxon and pauses,",
                frm.MSG_FONT, frm.MSG_BRUSH, (int)COMMOD9.lft, (int)COMMOD9.btm + 60);

            g.DrawString("  use [←] [→] keys to review taxa manually,",
               frm.MSG_FONT, frm.MSG_BRUSH, (int)COMMOD9.lft, (int)COMMOD9.btm + 80);

            g.DrawString("  or use [Esc] key to advance to summary screens",
                frm.MSG_FONT, frm.MSG_BRUSH, (int)COMMOD9.lft, (int)COMMOD9.btm + 100);

            g.DrawString("   [strike [Enter] key to continue]",
                frm.MSG_FONT, frm.MSG_BRUSH, (int)COMMOD9.lft, (int)COMMOD9.btm + 130);

            if (COMMOD9.CONTRACT != 0)
            {
                g.DrawString("  RANGE CONTRACTIONS ALLOWED!     ",
                    frm.MSG_FONT, Brushes.Magenta, (int)COMMOD9.lft, (int)COMMOD9.btm + 220);

                g.DrawString("         - observed ranges may extend beyond composite range",
                    frm.MSG_FONT, Brushes.Magenta, (int)COMMOD9.lft * 2, (int)COMMOD9.btm + 240);

                g.DrawString("         - the histograms and graphs may be compromised",
                    frm.MSG_FONT, Brushes.Magenta, (int)COMMOD9.lft * 2, (int)COMMOD9.btm + 260);
            }
        }
Exemple #12
0
        private void EVNTLBLINC(frmCONOP frm, Graphics g, int mI, int mJ)
        {
            COMMOD COMMOD9 = COMMOD.Singleton();
            string etitl = "";
            Brush brush = frm.MSG_BRUSH_7;

            if (COMMOD9.ISTATIC[mI, mJ, 0] > -1) brush = frm.MSG_BRUSH_12;
            Helper.GETEVNT(mI, ref etitl, 1, 1, 0, 0, 0, 0);
            if (COMMOD9.IROWS[mI, 1] == 3)
            {
                etitl = etitl.Trim() + ": MID-range event";
            }
            else if ((COMMOD9.IROWS[mI, 1] == 11) || (COMMOD9.IROWS[mI, 1] == 12))
            {
                etitl = etitl.Trim() + ": local uncertainties in red";
            }
            else if ((COMMOD9.IROWS[mI, 1] != 1) && (COMMOD9.IROWS[mI, 1] != 2))
            {
                etitl = etitl.Trim() + ": unpaired event";
            }
            else
            {
                etitl = etitl.Trim() + ":  local ranges in red";
            }

            g.DrawString(etitl, frm.MSG_FONT, brush, (int)COMMOD9.lft, (int)(COMMOD9.maxy - COMMOD9.btm * 3 / 4));

            g.DrawString("[←] [→] keys change taxon;   [↑] [↓] keys change composite scale;  [Esc] key exits loop",
                frm.MSG_FONT_S, frm.MSG_BRUSH, 10, (int)(COMMOD9.maxy - COMMOD9.btm / 3));
        }
Exemple #13
0
        public void DO5(frmCONOP frm, Graphics g,ref int JDelta, ref int evtDelta)
        {
            //draw the grand dimensionless range support

            COMMOD COMMOD9=COMMOD.Singleton();

            L = 1 + evtDelta;
            M=2;
            J = COMMOD9.NSCT + 1 - 1 + JDelta;

            //LOAD GRAND() in three loops
            //1.Section Loop------
            if (J > COMMOD9.NSCT-1)
            {
                //calculate the grand-average dimensionless support into GRAND()
                Helper.SetVal(GRAND, 0);
                N = 0;
                RNG = 0;
                RRNG = 0.00;

                //----set the composite scale--------------------------
                topx = COMMOD9.COMPLVL[COMMOD9.HLEVEL[J], J - COMMOD9.NSCT];
                btmx = 1000;
                scalx = 10000 / (topx - btmx);

                //2.Taxon Loop-----------
                for (IG = 0; IG < COMMOD9.NSPC; IG++)
                {
                    for (KG = 0; KG < COMMOD9.NEVNT; KG++)
                    {
                        if (INCRALL[IG, KG] > 0) break;
                    }
                    FADLVL = KG;

                    for (KG = COMMOD9.NEVNT - 1; KG >= 0; KG--)
                    {
                        if (INCRALL[IG, KG] > 0) break;
                    }
                    LADLVL = KG;

                    //toss out taxa with ranges extending beyond the composite
                    //use a 2-level cushion
                    if ((J - COMMOD9.NSCT == 0) &&
                        ((FADLVL <= 1) || (LADLVL >= COMMOD9.NEVNT - 2))) continue;

                    //toss out obvious errors
                    if (FADLVL > LADLVL) continue;

                    RNG = LADLVL - FADLVL + 1;
                    RRNG = COMMOD9.COMPLVL[LADLVL, J - COMMOD9.NSCT] - COMMOD9.COMPLVL[FADLVL, J - COMMOD9.NSCT];

                    //cull the taxon ranges
                    if (RNG < (5 * (L - 1))) continue;

                    N++;

                    //3.Event Level Loop------------
                    for (K = 0; K < COMMOD9.NEVNT; K++)
                    {
                        //don't plot histogram for non-range (unpaired) events

                        if (INCRALL[IG, K] == 0) continue;

                        valx = COMMOD9.COMPLVL[K, J - COMMOD9.NSCT];
                        stepup = (COMMOD9.COMPLVL[Math.Min(COMMOD9.NEVNT - 1, K + 1), J - COMMOD9.NSCT] +
                            COMMOD9.COMPLVL[K, J - COMMOD9.NSCT]) / 2.00;
                        stepdn = (COMMOD9.COMPLVL[Math.Max(0, K - 1), J - COMMOD9.NSCT] +
                            COMMOD9.COMPLVL[K, J - COMMOD9.NSCT]) / 2.00;

                        //4. GRAND() Loop
                        for (GG = Math.Max(0, (int)((stepdn - COMMOD9.COMPLVL[FADLVL, J - COMMOD9.NSCT]) * 10000 / RRNG));
                            GG < Math.Min(10000, (int)((stepup - COMMOD9.COMPLVL[FADLVL, J - COMMOD9.NSCT]) * 10000 / RRNG));
                            GG++)
                        {
                            if (M == 2)
                            {
                                GRAND[GG] += INCRALL[IG, K];
                            }
                            else if (M == 3)
                            {
                                GRAND[GG] += (int)(100.0 * (double)(INCRALL[IG, K]) / (double)(Math.Max(COMMOD9.COVER[K], 1)));
                            }
                        }
                    }
                }

                g.Clear(frm.BackColor);

                //draw axes
                g.DrawLine(frm.DRAW_PEN, (int)(COMMOD9.maxx - COMMOD9.rit), (int)(COMMOD9.maxy - COMMOD9.btm),
                    (int)COMMOD9.lft, (int)(COMMOD9.maxy - COMMOD9.btm));

                //do titles
                g.DrawString("first-appearance", frm.MSG_FONT_S, frm.MSG_BRUSH, (int)(COMMOD9.lft - 10), (int)(COMMOD9.maxy - COMMOD9.btm + 10));
                g.DrawString("last-appearance", frm.MSG_FONT_S, frm.MSG_BRUSH, (int)(COMMOD9.maxx - COMMOD9.rit - 20), (int)(COMMOD9.maxy - COMMOD9.btm + 10));

                Output.COMPLBL(J+1, ref xtitle);
                g.DrawString(xtitle, frm.MSG_FONT, frm.MSG_BRUSH, (int)(COMMOD9.lft + (COMMOD9.maxx - COMMOD9.lft) / 2),
                    (int)(COMMOD9.maxy - COMMOD9.btm / 2));

                g.DrawString("[←] [→] keys change taxon;   [↑] [↓] keys change composite scale;  [Esc] key exits loop",
                    frm.MSG_FONT_S, frm.MSG_BRUSH, (int)(COMMOD9.lft * 2), (int)(COMMOD9.maxy - COMMOD9.btm / 2));

                g.DrawString("DIMENSIONLESS RANGE SUPPORT -  Stacked for All Taxa", frm.MSG_FONT, frm.MSG_BRUSH,
                    (int)(COMMOD9.maxx / 5), (int)(COMMOD9.maxy / 10));

                if (M == 2)
                {
                    g.DrawString("Y-Axis:  Number of Sections", frm.MSG_FONT_S, frm.MSG_BRUSH,
                        (int)(COMMOD9.maxx / 5), (int)(COMMOD9.maxy / 10 + 20));
                }
                else if (M == 3)
                {
                    g.DrawString("Y-Axis:  Proportion of Sections", frm.MSG_FONT_S, frm.MSG_BRUSH,
                       (int)(COMMOD9.maxx / 5), (int)(COMMOD9.maxy / 10 + 20));
                }

                ntitle = string.Format("{0}", 5 * (L - 1));

                if (Helper.MAXVal(GRAND) <= 0)
                {
                    g.DrawString("No taxon ranges are longer than " + ntitle.Trim() + " events", frm.MSG_FONT_S, frm.MSG_BRUSH,
                        (int)(COMMOD9.maxx / 2), (int)(COMMOD9.maxy / 2));
                }
                else
                {
                    g.DrawString("Eliminates taxon ranges shorter than " + ntitle.Trim() + " events;     [←] [→] keys change threshold",
                        frm.MSG_FONT_S, frm.MSG_BRUSH, (int)(COMMOD9.maxx / 4), (int)(COMMOD9.maxy / 5));

                    ntitle = string.Format("{0}", N);
                    g.DrawString(ntitle + " taxa in stack", frm.MSG_FONT_S, frm.MSG_BRUSH, (int)(COMMOD9.maxx / 4), (int)((COMMOD9.maxy / 5) + 20));

                    for (GG = 0; GG < 10000; GG++)
                    {
                        int x1 = (int)(COMMOD9.lft + (double)(COMMOD9.maxx - COMMOD9.lft - COMMOD9.rit) * (double)(GG) / 10000.0);
                        int y1 = (int)(COMMOD9.maxy - COMMOD9.btm - 1);
                        int x2 = (int)(COMMOD9.lft + (double)(COMMOD9.maxx - COMMOD9.lft - COMMOD9.rit) * (double)(GG + 1) / 10000.0);
                        int y2 = (int)((double)(COMMOD9.maxy - COMMOD9.btm - 1) -
                            (double)(COMMOD9.maxy / 2) * (double)(GRAND[GG]) / (double)(Helper.MAXVal(GRAND)));

                        if (x1 != x2)
                        {
                            g.FillRectangle(frm.MSG_BRUSH_AAAAAA, Math.Min(x1, x2), Math.Min(y1, y2),
                                Math.Abs(x1 - x2), Math.Abs(y1 - y2));
                        }
                        else
                        {
                            g.DrawLine(frm.DRAW_PEN_AAAAAA, x1, y1, x2, y2);
                        }
                    }

                }
            }
        }
Exemple #14
0
        public void DO4(frmCONOP frm, Graphics g,ref int LDelta)
        {
            //now plot the diversity against the per taxon average support.
            COMMOD COMMOD9=COMMOD.Singleton();
            L=2+LDelta;

            if(L!=0)
            {
                if(L==2)
                {
                    g.Clear(frm.BackColor);

                    //draw axes
                    g.DrawLine(frm.DRAW_PEN,(int)(COMMOD9.maxx-COMMOD9.rit),(int)(COMMOD9.maxy-COMMOD9.btm),
                        (int)(COMMOD9.lft),(int)(COMMOD9.maxy-COMMOD9.btm));
                    g.DrawLine(frm.DRAW_PEN, (int)(COMMOD9.lft), (int)(COMMOD9.maxy - COMMOD9.btm),
                        (int)(COMMOD9.lft),(int)(COMMOD9.top));

                    ntitle=string.Format("{0,6:0.00}",Helper.MAXVal(INCREAL));
                    g.DrawString("max = "+ntitle.Trim(),frm.MSG_FONT,frm.MSG_BRUSH,
                        (int)(COMMOD9.maxx-COMMOD9.rit-10),(int)(COMMOD9.maxy-COMMOD9.btm+10));

                    g.DrawString("AVERAGE NUMBER OF OBSERVED RANGE INCREMENTS PER TAXON",frm.MSG_FONT,frm.MSG_BRUSH,
                        (int)(COMMOD9.maxx/4),(int)(COMMOD9.maxy-(COMMOD9.btm/2)));

                    ntitle=string.Format("{0}",Helper.MAXVal(INCRN));
                    g.DrawString("max = "+ntitle.Trim(),frm.MSG_FONT,frm.MSG_BRUSH,
                        (int)(COMMOD9.lft/4),(int)(COMMOD9.top+3));

                    g.TranslateTransform((int)(COMMOD9.lft/4),(int)(COMMOD9.maxy-COMMOD9.btm-COMMOD9.btm));
                    g.RotateTransform(vert);
                    g.DrawString("TAXON RICHNESS (not composite range-through)",frm.MSG_FONT,frm.MSG_BRUSH,0,0);
                    g.ResetTransform();

                    g.TranslateTransform((int)(COMMOD9.lft/2),(int)(COMMOD9.maxy-COMMOD9.btm-COMMOD9.btm));
                    g.RotateTransform(vert);
                    g.DrawString(" one symbol for each event-level in composite sequence",frm.MSG_FONT_S,frm.MSG_BRUSH,0,0);
                    g.ResetTransform();

                    for(K=0;K<COMMOD9.NEVNT;K++)
                    {
                        if(INCRN[K]==0)continue;
                        if(INCREAL[K]==0.0)continue;

                        int x1=(int)((double)(COMMOD9.lft)-3+(double)(COMMOD9.maxx-COMMOD9.lft-COMMOD9.rit)*
                            INCREAL[K]/Helper.MAXVal(INCREAL));
                        int y1=(int)((double)(COMMOD9.maxy-COMMOD9.btm-3)-(double)(COMMOD9.maxy-COMMOD9.top-COMMOD9.btm)*
                            (double)(INCRN[K])/(double)(Helper.MAXVal(INCRN)));
                        int x2=(int)((double)(COMMOD9.lft)+3+(double)(COMMOD9.maxx-COMMOD9.lft-COMMOD9.rit)*
                            INCREAL[K]/Helper.MAXVal(INCREAL));
                        int y2=(int)((double)(COMMOD9.maxy-COMMOD9.btm+3)-(double)(COMMOD9.maxy-COMMOD9.top-COMMOD9.btm)*
                            (double)(INCRN[K])/(double)(Helper.MAXVal(INCRN)));

                        g.DrawRectangle(frm.DRAW_PEN,Math.Min(x1,x2),Math.Min(y1,y2),Math.Abs(x1-x2),Math.Abs(y1-y2));

                         x1=(int)((double)(COMMOD9.lft)-2+(double)(COMMOD9.maxx-COMMOD9.lft-COMMOD9.rit)*
                            INCREAL[K]/Helper.MAXVal(INCREAL));
                         y1=(int)((double)(COMMOD9.maxy-COMMOD9.btm-2)-(double)(COMMOD9.maxy-COMMOD9.top-COMMOD9.btm)*
                            (double)(INCRN[K])/(double)(Helper.MAXVal(INCRN)));
                         x2=(int)((double)(COMMOD9.lft)+2+(double)(COMMOD9.maxx-COMMOD9.lft-COMMOD9.rit)*
                            INCREAL[K]/Helper.MAXVal(INCREAL));
                         y2=(int)((double)(COMMOD9.maxy-COMMOD9.btm+2)-(double)(COMMOD9.maxy-COMMOD9.top-COMMOD9.btm)*
                            (double)(INCRN[K])/(double)(Helper.MAXVal(INCRN)));

                        g.FillRectangle(frm.MSG_BRUSH_CCCCFF,Math.Min(x1,x2),Math.Min(y1,y2),Math.Abs(x1-x2),Math.Abs(y1-y2));

                    }

                    //cpms  scale the x-axis
                    g.DrawLine(frm.DRAW_PEN,(int)(COMMOD9.lft),(int)(COMMOD9.maxy-COMMOD9.btm),
                        (int)(COMMOD9.lft),(int)(COMMOD9.maxy-COMMOD9.btm+2));

                    J=1;
                    while((double)J<Helper.MAXVal(INCREAL))
                    {
                        g.DrawLine(frm.DRAW_PEN,
                            (int)(COMMOD9.lft+(double)J*(double)(COMMOD9.maxx-COMMOD9.lft-COMMOD9.rit)/Helper.MAXVal(INCREAL)),
                            (int)(COMMOD9.maxy-COMMOD9.btm),
                            (int)(COMMOD9.lft+(double)J*(double)(COMMOD9.maxx-COMMOD9.lft-COMMOD9.rit)/Helper.MAXVal(INCREAL)),
                            (int)(COMMOD9.maxy-COMMOD9.btm+5)
                            );

                        J++;
                    }

                    //cpms  scale the y-axis
                    g.DrawLine(frm.DRAW_PEN,(int)(COMMOD9.lft),(int)(COMMOD9.maxy-COMMOD9.btm),
                        (int)(COMMOD9.lft),(int)(COMMOD9.maxy-COMMOD9.btm+2));

                    J=1;
                    while((double)J<Helper.MAXVal(INCRN))
                    {
                        g.DrawLine(frm.DRAW_PEN,
                            (int)(COMMOD9.lft),
                            (int)((double)(COMMOD9.maxy-COMMOD9.btm)-(double)J*(double)(COMMOD9.maxy-COMMOD9.btm-COMMOD9.top)/Helper.MAXVal(INCRN)),
                            (int)(COMMOD9.lft-5),
                            (int)((double)(COMMOD9.maxy-COMMOD9.btm)-(double)J*(double)(COMMOD9.maxy-COMMOD9.btm-COMMOD9.top)/Helper.MAXVal(INCRN))
                            );

                        J++;
                    }

                }
                else if(L==3)
                {
                    //CPMS   ------------------------------------------------------------------
                    //cpms   now plot the diversity against the per section average support.
                    g.Clear(frm.BackColor);

                    //draw axes
                    g.DrawLine(frm.DRAW_PEN,(int)(COMMOD9.maxx-COMMOD9.rit),(int)(COMMOD9.maxy-COMMOD9.btm),
                        (int)(COMMOD9.lft),(int)(COMMOD9.maxy-COMMOD9.btm));
                    g.DrawLine(frm.DRAW_PEN, (int)(COMMOD9.lft), (int)(COMMOD9.maxy - COMMOD9.btm),
                        (int)(COMMOD9.lft),(int)(COMMOD9.top));

                    ntitle=string.Format("{0,6:0.00}",Helper.MAXVal(SINCREAL));
                    g.DrawString("max = "+ntitle.Trim(),frm.MSG_FONT,frm.MSG_BRUSH,
                        (int)(COMMOD9.maxx-COMMOD9.rit-10),(int)(COMMOD9.maxy-COMMOD9.btm+10));

                    g.DrawString("AVERAGE SINGLE-SECTION TAXON RICHNESS;   i.e. "+
                    "number of range increments per section",frm.MSG_FONT,frm.MSG_BRUSH,
                        (int)(COMMOD9.maxx/4),(int)(COMMOD9.maxy-(COMMOD9.btm/2)));

                    ntitle=string.Format("{0}",Helper.MAXVal(INCRN));
                    g.DrawString("max = "+ntitle.Trim(),frm.MSG_FONT,frm.MSG_BRUSH,
                        (int)(COMMOD9.lft/4),(int)(COMMOD9.top+3));

                    g.TranslateTransform((int)(COMMOD9.lft/4),(int)(COMMOD9.maxy-COMMOD9.btm-COMMOD9.btm));
                    g.RotateTransform(vert);
                    g.DrawString("COMPOSITE TAXON RICHNESS (not composite range-through)",frm.MSG_FONT,frm.MSG_BRUSH,0,0);
                    g.ResetTransform();

                    g.TranslateTransform((int)(COMMOD9.lft/2),(int)(COMMOD9.maxy-COMMOD9.btm-COMMOD9.btm));
                    g.RotateTransform(vert);
                    g.DrawString(" one symbol for each event-level in composite sequence",frm.MSG_FONT_S,frm.MSG_BRUSH,0,0);
                    g.ResetTransform();

                    for(K=0;K<COMMOD9.NEVNT;K++)
                    {
                        if(SINCRN[K]==0)continue;
                        if(SINCREAL[K]==0.0)continue;

                        int x1=(int)((double)(COMMOD9.lft)-3+(double)(COMMOD9.maxx-COMMOD9.lft-COMMOD9.rit)*
                            SINCREAL[K]/Helper.MAXVal(SINCREAL));
                        int y1=(int)((double)(COMMOD9.maxy-COMMOD9.btm-3)-(double)(COMMOD9.maxy-COMMOD9.top-COMMOD9.btm)*
                            (double)(INCRN[K])/(double)(Helper.MAXVal(INCRN)));
                        int x2=(int)((double)(COMMOD9.lft)+3+(double)(COMMOD9.maxx-COMMOD9.lft-COMMOD9.rit)*
                            SINCREAL[K]/Helper.MAXVal(SINCREAL));
                        int y2=(int)((double)(COMMOD9.maxy-COMMOD9.btm+3)-(double)(COMMOD9.maxy-COMMOD9.top-COMMOD9.btm)*
                            (double)(INCRN[K])/(double)(Helper.MAXVal(INCRN)));

                        g.DrawRectangle(frm.DRAW_PEN,Math.Min(x1,x2),Math.Min(y1,y2),Math.Abs(x1-x2),Math.Abs(y1-y2));

                         x1=(int)((double)(COMMOD9.lft)-2+(double)(COMMOD9.maxx-COMMOD9.lft-COMMOD9.rit)*
                            SINCREAL[K]/Helper.MAXVal(SINCREAL));
                         y1=(int)((double)(COMMOD9.maxy-COMMOD9.btm-2)-(double)(COMMOD9.maxy-COMMOD9.top-COMMOD9.btm)*
                            (double)(INCRN[K])/(double)(Helper.MAXVal(INCRN)));
                         x2=(int)((double)(COMMOD9.lft)+2+(double)(COMMOD9.maxx-COMMOD9.lft-COMMOD9.rit)*
                            SINCREAL[K]/Helper.MAXVal(SINCREAL));
                         y2=(int)((double)(COMMOD9.maxy-COMMOD9.btm+2)-(double)(COMMOD9.maxy-COMMOD9.top-COMMOD9.btm)*
                            (double)(INCRN[K])/(double)(Helper.MAXVal(INCRN)));

                        g.FillRectangle(frm.MSG_BRUSH_FFCCCC,Math.Min(x1,x2),Math.Min(y1,y2),Math.Abs(x1-x2),Math.Abs(y1-y2));

                    }

                    //cpms  show 45-degree line
                    frm.DRAW_PEN_7.DashStyle=System.Drawing.Drawing2D.DashStyle.Dash;
                    g.DrawLine(frm.DRAW_PEN_7,(int)(COMMOD9.lft+1),(int)(COMMOD9.maxy-COMMOD9.btm-1),
                        (int)(COMMOD9.maxx-COMMOD9.rit),(int)((double)(COMMOD9.maxy - COMMOD9.btm)-
                        (double)(COMMOD9.maxy-COMMOD9.btm-COMMOD9.top)*
                        Helper.MAXVal(SINCREAL)/(double)(Helper.MAXVal(INCRN))));
                    frm.DRAW_PEN_7.DashStyle=System.Drawing.Drawing2D.DashStyle.Solid;

                    g.DrawString(" slope = 1",frm.MSG_FONT_S,frm.MSG_BRUSH_7,
                        (int)(COMMOD9.maxx - COMMOD9.rit + 1), (int)((double)(COMMOD9.maxy - COMMOD9.btm) -
                        (double)(COMMOD9.maxy-COMMOD9.btm-COMMOD9.top)*
                        Helper.MAXVal(SINCREAL)/(double)(Helper.MAXVal(INCRN))-5));

                    g.DrawString(" PLOTS IMPOSSIBLE BELOW LINE",frm.MSG_FONT_S,frm.MSG_BRUSH_7,
                        (int)(COMMOD9.maxx*3/4),(int)((double)(COMMOD9.maxy-COMMOD9.btm)-
                        (double)(COMMOD9.maxy-COMMOD9.btm-COMMOD9.top)*Helper.MAXVal(SINCREAL)/
                        (double)(Helper.MAXVal(INCRN))/2-5));

                    //cpms  scale the x-axis
                    g.DrawLine(frm.DRAW_PEN,(int)(COMMOD9.lft),(int)(COMMOD9.maxy-COMMOD9.btm),
                        (int)(COMMOD9.lft),(int)(COMMOD9.maxy-COMMOD9.btm+2));

                    J=1;
                    while((double)J<Helper.MAXVal(SINCREAL))
                    {
                        g.DrawLine(frm.DRAW_PEN,
                            (int)(COMMOD9.lft+(double)J*(double)(COMMOD9.maxx-COMMOD9.lft-COMMOD9.rit)/Helper.MAXVal(SINCREAL)),
                            (int)(COMMOD9.maxy-COMMOD9.btm),
                            (int)(COMMOD9.lft+(double)J*(double)(COMMOD9.maxx-COMMOD9.lft-COMMOD9.rit)/Helper.MAXVal(SINCREAL)),
                            (int)(COMMOD9.maxy-COMMOD9.btm+5)
                            );

                        J++;
                    }

                    //cpms  scale the y-axis
                    g.DrawLine(frm.DRAW_PEN,(int)(COMMOD9.lft),(int)(COMMOD9.maxy-COMMOD9.btm),
                        (int)(COMMOD9.lft),(int)(COMMOD9.maxy-COMMOD9.btm+2));

                    J=1;
                    while((double)J<Helper.MAXVal(INCRN))
                    {
                        g.DrawLine(frm.DRAW_PEN,
                            (int)(COMMOD9.lft),
                            (int)((double)(COMMOD9.maxy-COMMOD9.btm)-(double)J*(double)(COMMOD9.maxy-COMMOD9.btm-COMMOD9.top)/Helper.MAXVal(INCRN)),
                            (int)(COMMOD9.lft-5),
                            (int)((double)(COMMOD9.maxy-COMMOD9.btm)-(double)J*(double)(COMMOD9.maxy-COMMOD9.btm-COMMOD9.top)/Helper.MAXVal(INCRN))
                            );

                        J++;
                    }

                }

                // X-AXIS SUB-TITLE     do composite title
                g.DrawString("[←] [→] keys reveal 1 more plot;   [Esc] key exits loop",
                    frm.MSG_FONT_S,frm.MSG_BRUSH,10,(int)(COMMOD9.maxy-COMMOD9.btm/2));

            }
        }
Exemple #15
0
        private void EDITCHT(frmCONOP frm, Graphics g, int ranki, int rankj)
        {
            COMMOD COMMOD9 = COMMOD.Singleton();
            int rankt;
            int typei, typej, typet;
            // limits of screen resolution:   maxx  maxy
            //   margins outside graph box:   top  btm  lft  rit

            int scl = 0;
            int top = 0;
            int btm = 50;
            int lft = 100;
            int rit = 0;

            //CPMS---------------------------------------------------------------------
            //CPMS  Edit the range lines
            typei = COMMOD9.IROWS[COMMOD9.LSTPERM[ranki], 1];
            typej = COMMOD9.IROWS[COMMOD9.LSTPERM[rankj], 1];

            //CPMS---------------------------------------------------------------------
            //CPMS  CASE 1  ranki moves up to j; intermediates move down 1 rank
            //CPMS---------------------------------------------------------------------
            if (ranki < rankj)
            {
                //edit ranki to  rankj regardless of neighborhood size
                if ((typei == 1) || (typei == 2) || (typei == 11) || (typei == 12))
                {
                    //ranki is a paired range end;  edit bar
                    //if ranki is a FAD or MAX; range base must be blanked up to rankj
                    //if ranki is a last; range top must be extended in white/gold
                    frm.SetColor(0);
                    if (typei == 2) frm.SetColor(15);
                    if (typei == 12) frm.SetColor(14);

                    CLIP(frm, g, ranki, ranki, rankj);

                }
                else if ((typei > 3) || (typei < 1))
                {
                    //ranki is an unpaired event;  move dash up
                    NEWDASH(frm, g, ranki, ranki, rankj, 0, 14);
                }
                else if (typei == 3)
                {
                    NEWDASH(frm, g, ranki, ranki, rankj, 15, 12);
                }

                //CPMS   if ranks j and i switch
                if (COMMOD9.NABRGEN > 1)
                {
                    //edit rankj to ranki
                    if ((typej == 1) || (typej == 2) || (typej == 11) || (typej == 12))
                    {
                        //rankj is a paired range end;  edit bar
                        //if rankj is a first: extend base of range bar
                        //if ranki is a last; blank out range end

                        frm.SetColor(15);

                        if (typej == 11) frm.SetColor(14);
                        if (typej == 2) frm.SetColor(0);
                        if (typej == 12) frm.SetColor(0);

                        CLIP(frm, g, ranki, rankj, rankj);
                    }
                    else if ((typej > 3) || (typej < 1))
                    {
                        //rankj is an unpaired event;  move dash down
                        NEWDASH(frm, g, rankj, rankj, ranki, 0, 14);
                    }
                    else if (typej == 3)
                    {
                        NEWDASH(frm, g, rankj, rankj, ranki, 15, 12);
                    }
                }

                //CPMS   if making big single moves
                if (COMMOD9.NABRGEN == 1)
                {
                    rankt = ranki + 1;

                    while (rankt <= rankj)
                    {
                        typet = COMMOD9.IROWS[COMMOD9.LSTPERM[rankt], 1];

                        //move all intermediate events down 1 rank
                        if ((typet == 1) || (typet == 2) || (typet == 11) || (typet == 12))
                        {
                            //if rankt is a first; extend the range bar down 1 rank
                            //if rankt is a last; blank range bar down one rank from top
                            frm.SetColor(15);
                            if (typet == 11) frm.SetColor(14);
                            if (typet == 2) frm.SetColor(0);
                            if (typet == 12) frm.SetColor(0);
                            CLIP(frm, g, rankt - 1, rankt, rankt);
                        }
                        else if ((typet > 3) || (typet < 1))
                        {
                            //rankt is an unpaired event, move dash down 1
                            NEWDASH(frm, g, rankt, rankt, rankt - 1, 0, 14);
                        }
                        else if (typet == 3)
                        {
                            NEWDASH(frm, g, rankt, rankt, rankt - 1, 15, 12);
                        }

                        rankt++;
                    }
                }
            }
            else if (ranki > rankj)
            {
                //CPMS----------------------------------------------------------------------
                //CPMS   CASE 2  ranki moves down to j and intermediate ranks move up 1 rank
                //CPMS----------------------------------------------------------------------

                //edit ranki to rankj regardless of neighborhood size
                if ((typei == 1) || (typei == 2) || (typei == 11) || (typei == 12))
                {
                    //ranki is a paired range end;  edit bar
                    //if ranki is a first; extend base of range bar
                    //if ranki is a last; blank out range end
                    frm.SetColor(15);
                    if (typei == 11) frm.SetColor(14);
                    if (typei == 2) frm.SetColor(0);
                    if (typei == 12) frm.SetColor(0);

                    CLIP(frm, g, rankj, ranki, ranki);
                }
                else if ((typei > 3) || (typei < 1))
                {
                    //ranki is an unpaired event;  move dash down
                    NEWDASH(frm, g, ranki, ranki, rankj, 0, 14);
                }
                else if (typei == 3)
                {
                    NEWDASH(frm, g, ranki, ranki, rankj, 15, 15);
                }

                //CPMS   if ranks j and i switch:
                if (COMMOD9.NABRGEN > 1)
                {
                    //edit rankj to ranki if making double switch
                    if ((typej == 1) || (typej == 2) || (typej == 11) || (typej == 12))
                    {
                        //rankj is a paired range end;  edit bar
                        //if rankj is a first; range base must be blanked up to ranki
                        //if rankj is a last; range top must be extended
                        frm.SetColor(0);
                        if (typej == 2) frm.SetColor(15);
                        if (typej == 12) frm.SetColor(14);

                        //move to left end (j) of modification
                        CLIP(frm, g, rankj, rankj, ranki);
                    }
                    else if ((typej > 3) || (typej < 1))
                    {
                        //rankj is an unpaired event;  move dash up
                        NEWDASH(frm, g, rankj, rankj, ranki, 0, 14);
                    }
                    else if (typej == 3)
                    {
                        NEWDASH(frm, g, rankj, rankj, ranki, 15, 12);
                    }
                }

                //if making big single moves (BIGNABR)
                if (COMMOD9.NABRGEN == 1)
                {
                    rankt = ranki - 1;
                    while (rankt >= rankj)
                    {
                        typet = COMMOD9.IROWS[COMMOD9.LSTPERM[rankt], 1];

                        //intermediate ranks move up 1 rank
                        if ((typet == 1) || (typet == 2) || (typet == 11) || (typet == 12))
                        {
                            //if rankt is a first; blank out range start
                            //if rankt is a last; extend end of range bar
                            frm.SetColor(0);
                            if (typet == 2) frm.SetColor(15);
                            if (typet == 12) frm.SetColor(14);

                            //move to left end (t) of modification
                            CLIP(frm, g, rankt, rankt, rankt + 1);
                        }
                        else if ((typet > 3) || (typet < 1))
                        {
                            //rankt is an unpaired event, move dash up 1
                            NEWDASH(frm, g, rankt, rankt, rankt + 1, 0, 14);
                        }
                        else if (typet == 3)
                        {
                            NEWDASH(frm, g, rankt, rankt, rankt + 1, 15, 12);
                        }

                        rankt--;
                    }
                }
            }

            //CPMS--------------------------------
            //CPMS  restore default graphics mode

            frm.SetColor(15);
        }
Exemple #16
0
        public void RunIt(frmCONOP frm)
        {
            double DELTA;

            double U;
            int INNER, IRANK, JRANK, LAST, OUTER, NCTR, FIXM, NABRM;
            int I, L, X, NCT;

            //CPMS  Declarations for graphics:
            //CPMS  PCT  Percentage annealed
            //CPMS  INISCOR - extension penalty for initial solution
            //CPMS  BSTSCOR - best extension penalty to date
            //CPMS  SCORes do not include the smoothing factors
            //CPMS  I??SCOR - initial scores for scaling the screen plots

            int INISCOR, ISMSCOR, ISQSCOR, ISHSCOR, ITSSCOR, INGSCOR;
            int BSTSCOR, AUTSCOR;
            double PCT;
            int dummy, ulx, uly, lrx, lry, res, siz;
            string SCORE;

            int horiz, vert, div;
            bool rndf, stepf, aimf, redf, trjf, algf, rlxf, rngf, hilf, s45f, s67f, s89f;

            COMMOD COMMOD9 = COMMOD.Singleton();

            //CPMS************************************************
            //CPMS***PRELIMINARIES
            //CPMS	 next section executes only once in a run
            //CPMS------------------------------------------------

            div = 0;

            //C     initialize things for Intel 11.1
            COMMOD9.UU = 0.0;
            U = 0.0;
            PCT = 0.0;
            DELTA = 0.0;
            INNER = 0;
            IRANK = 0;
            JRANK = 0;
            LAST = 0;
            OUTER = 0;
            NCTR = 0;
            FIXM = 0;
            NABRM = 0;
            I = 0;
            L = 0;
            X = 0;
            NCT = 0;

            //C   initialized for Intel 9.0
            horiz = 0;
            vert = 900;
            rndf = true;
            INISCOR = 0;
            ITSSCOR = 0;
            ISMSCOR = 0;
            ISQSCOR = 0;
            ISHSCOR = 0;
            INGSCOR = 0;
            AUTSCOR = 0;
            BSTSCOR = 0;

            if ((COMMOD9.AUTF == 0) && (COMMOD9.CONTF == 0))
            {
                COMMOD9.BSTPEN = 0.0;
                COMMOD9.BS2PEN = 0.0;
            }

            COMMOD9.TOOPEN = 0.0;
            COMMOD9.TO2PEN = 0.0;
            COMMOD9.TSPEN = 0.0;
            COMMOD9.SMPEN = 0.0;
            COMMOD9.SHPEN = 0.0;
            COMMOD9.CRTPEN = 0.0;
            COMMOD9.NEWRANK = 0;
            //c  NEWRANK is the rank to which the last (BIG|SML) mutation moved an event

            //C--------------------------------
            //C     set loop-accelerator flags
            //C     step-solutions (outer loop):
            stepf = false;
            if ((COMMOD9.STEPSOL.Substring(0, 3) != "OFF") && (COMMOD9.STEPSOL.Substring(0, 3) != "off"))
            {
                stepf = true;
            }

            //C  aimed tempering (outer loop):

            aimf = false;
            if ((COMMOD9.SOLVEF == 3) && (COMMOD9.FIXF == 2)) aimf = true;

            //C  animated ranges:
            rngf = false;
            if ((COMMOD9.RUNGRF == 2) || (COMMOD9.RUNGRF == 5)) rngf = true;

            //C  penalty trajectory:
            trjf = false;
            if (((COMMOD9.RUNGRF == 2) || (COMMOD9.RUNGRF == 0)) && (COMMOD9.TRJGRF > 0)) trjf = true;

            //C  red temp curve (inner loop):
            redf = false;
            if (trjf)
            {
                if ((COMMOD9.RUNGRF != 0) && (COMMOD9.SOLVEF != 2) && (COMMOD9.SOLVEF != 4) &&
                   (COMMOD9.SOLVEF != 6) && (COMMOD9.SOLVEF != 8)) redf = true;
            }

            //C  greedy algorithm:
            algf = false;
            if ((COMMOD9.SOLVEF == 2) || (COMMOD9.SOLVEF == 4) || (COMMOD9.SOLVEF == 6) ||
               (COMMOD9.SOLVEF == 8)) algf = true;

            //C  relaxed fit update:
            rlxf = false;
            if ((COMMOD9.RUNGRF >= 4) || (COMMOD9.GRIDF == 1)) rlxf = true;
            //C  uphill moves in different color:
            hilf = false;
            if ((COMMOD9.SOLVEF != 2) && (COMMOD9.TRJGRF >= 3)) hilf = true;

            //C  SOLVEF 4 or 5 (squeeze):
            s45f = false;
            if ((COMMOD9.SOLVEF == 4) || (COMMOD9.SOLVEF == 5)) s45f = true;

            //C  SOLVEF 6 or 7 (shrink)
            s67f = false;
            if ((COMMOD9.SOLVEF == 6) || (COMMOD9.SOLVEF == 7)) s67f = true;
            //C     SOLVEF 8 or 9 (stack)
            s89f = false;
            if ((COMMOD9.SOLVEF == 8) || (COMMOD9.SOLVEF == 9)) s89f = true;

            //C--------------------------------
            //C     set the initial temperature
            NCTR = 0;
            COMMOD9.CTRF = 0;
            COMMOD9.NBETR = 0;

            if (COMMOD9.CONTF == 1) goto Label111;

            switch (COMMOD9.AUTF)
            {
                case 0:
                    //cpms  not PAUSES='AUT','ADA'
                    COMMOD9.T = COMMOD9.STARTT;
                    break;
                case 1:
                    //cpms  still improving in last TRIALS - don't cool
                    //COMMOD9.T=COMMOD9.T;
                    COMMOD9.Rx = COMMOD9.R;
                    break;
                case -1:
                    //cpms   nothing better found in last TRIALS - cool
                    //c         The following line cools by a fixed amount
                    //c	        T = T*R
                    //c         In the alternative the size of the
                    //c         cooling step increases as the
                    //c         size of the null sets increases
                    //c         for adaprive cooling
                    COMMOD9.Rx = COMMOD9.R;
                    if ((COMMOD9.ADAF == 1) && (COMMOD9.NTRIES > 0) && (COMMOD9.LSTRIES > 1))
                    {
                        L = COMMOD9.RANDOM.Next(Math.Min(COMMOD9.LSTRIES, 5) + 1);//<=HXD
                        COMMOD9.Rx = Math.Pow(COMMOD9.R, L);
                        COMMOD9.NTRIES = COMMOD9.NTRIES + (L - 1);
                    }

                    COMMOD9.T = COMMOD9.T * COMMOD9.Rx;

                    break;
            }

            #if test_initPerm
            //INITPERM
            long _index = 0;

            #if SEC7
            string inputFile = "inData/SEC7_INIT_PERM.csv";
            #elif SEC19
            string inputFile = "inData/SEC19_INIT_PERM.csv";
            #elif SEC20
            string inputFile = "inData/SEC20_INIT_PERM.csv";
            #elif SEC50
            string inputFile = "inData/SEC50_INIT_PERM.csv";
            #elif SEC195
            string inputFile = "inData/SEC195_INIT_PERM.csv";
            #elif SEC286
            string inputFile = "inData/SEC286_INIT_PERM.csv";
            #elif SEC287
            string inputFile = "inData/SEC287_INIT_PERM.csv";
            #endif

            #if  REPACEPERM

            COMMOD9.INIPERM = new int[COMMOD9.NEVNT];
            using (StreamReader reader = new StreamReader(inputFile, Encoding.Default, true))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    COMMOD9.INIPERM[_index++] = int.Parse(line.Split(',')[1]);
                }
            }
            #endif
            #endif //test_initPerm

            Label111:
            PCT = COMMOD9.NINNER * COMMOD9.NOUTER;

            //C--------------------------------------------------------
            //CPMS  alter OUTF so that GETPEN does not write to outmain
            //CPMS
            //**      OUTF = OUTF-100
            //CPMS
            //C     COMPUTE THE BEST PLACEMENTS THAT COMPLY WITH STARTING PERM
            //C       "INIPERM" AND RESULTING PENALTY.
            //C          PUT THE placements in SCTSOL and the PENALTY IN PEN
            //C
            //C     for the first permutation, we need a complete solution.
            //C         for subsequent perms, we may use reoptimization.
            //C---------------------------------------------------------
            if (COMMOD9.PENF <= 1)
            {
                Helper.GETPEN(COMMOD9.INIPERM, ref COMMOD9.NXTPEN);
            }
            else if (COMMOD9.PENF >= 2)
            {
                Helper.DEMPEN(COMMOD9.INIPERM, ref COMMOD9.NXTPEN);
            }

            //CPMS*********************************************
            //CPMS  PRELIMINARIES  -  not included in loops
            Helper.CopyArray(COMMOD9.INIPERM, ref COMMOD9.PERM);
            Helper.CopyArray(COMMOD9.INIPERM, ref COMMOD9.LSTPERM);
            Helper.CopyArray(COMMOD9.INIPERM, ref COMMOD9.PXLPERM);

            if (COMMOD9.CONTF == 0) Helper.CopyArray(COMMOD9.INIPERM, ref COMMOD9.BSTPERM);

            COMMOD9.PEN = COMMOD9.NXTPEN;
            COMMOD9.INIPEN = COMMOD9.NXTPEN;
            INISCOR = (int)COMMOD9.INIPEN;
            AUTSCOR = (int)COMMOD9.NXTPEN;

            if (COMMOD9.AUTF == 0)
            {
                if (COMMOD9.CONTF == 0) COMMOD9.BSTPEN = COMMOD9.NXTPEN;
            }
            else
            {
                if (COMMOD9.CONTF == 0) COMMOD9.BSTPEN = COMMOD9.AUTPEN;
            }

            BSTSCOR = (int)COMMOD9.BSTPEN;

            //Helper.DOTOO();

            COMMOD9.NGTPEN = COMMOD9.NGHPEN;
            INGSCOR = (int)COMMOD9.NGTPEN;

            if ((COMMOD9.AUTF == 0) && (COMMOD9.CONTF == 0))
            {
                COMMOD9.BS2PEN = COMMOD9.TOOPEN;
                COMMOD9.SQBST = COMMOD9.SQPEN;
                COMMOD9.SHBST = COMMOD9.SHPEN;
                COMMOD9.TSBST = COMMOD9.TSPEN;
            }

            ISQSCOR = (int)COMMOD9.SQPEN;
            ISHSCOR = (int)COMMOD9.SHPEN;
            COMMOD9.TSLST = COMMOD9.TSPEN;
            ITSSCOR = (int)COMMOD9.TSPEN;

            ISMSCOR = (int)COMMOD9.SMPEN;

            if ((COMMOD9.KSM > 0.0) && (COMMOD9.PENF < 2))
            {
                ISMSCOR = (int)(COMMOD9.SMPEN / COMMOD9.KSM);
                INISCOR = (int)(COMMOD9.PEN - COMMOD9.SMPEN);
                BSTSCOR = (int)(COMMOD9.BSTPEN - COMMOD9.SMPEN);
            }

            if (COMMOD9.CTRF == 1)
            {
                NCT = NCT + 1;
                COMMOD9.CTRF = 0;
            }

            if (COMMOD9.GRID2F == 1)
            {
                //cpms	 make sure that the .gr2 file records initial permutation

                for (X = 0; X < COMMOD9.NEVNT; X++)
                {
                    //cpms  update secondary penalty
                    COMMOD9.SECNDBST[COMMOD9.PERM[X], X] =
                        Math.Min(COMMOD9.SECNDBST[COMMOD9.PERM[X], X], COMMOD9.TO2PEN);
                }
            }

            //C-----------------------------------------------------------------------
            //C     to speed up reoptimization (in EVALUATE), keep track of
            //C         the last action taken during annealing.
            //C     if the new PERM was accepted,
            //C         SCTSOL and HSCTSOL will already be the same, and there is no need
            //C         to copy SCTSOL to HSCTSOL before reoptimization.
            //C     if the new permutation is not accepted, copy SCTSOL to HSCTSOL
            //C     use the flag LAST:
            //C        LAST = 1, accepted the new PERM
            //C        LAST = 0, did not accept the new PERM
            //C     since GETPEN calculates HSCTSOL, and we assign that to SCTSOL,
            //C         initialize it to 1.
            //C-----------------------------------------------------------------------
            //C     put the initial perm in PERM, the initial penalty in PEN, and
            //C     USE PERM AND PEN AS THE INITIAL "BEST" VALUES
            //C-----------------------------------------------------------------------

            Helper.CopyArray(COMMOD9.HSCTSOL, ref COMMOD9.SCTSOL);
            Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);
            LAST = 1;
            COMMOD9.XPOSN = 0;

            if (COMMOD9.FIXF == 3)
            {
                for (COMMOD9.XPOSN = 0; COMMOD9.XPOSN < COMMOD9.NEVNT; COMMOD9.XPOSN++)
                {
                    if (COMMOD9.PERM[COMMOD9.XPOSN] == COMMOD9.XEVNT) break;
                }
            }

            //HACK:OMIT MANY LINES

            //cpms---reset CONTF after first pass through--------------

            COMMOD9.CONTF = 0;

            //CPMS*******************************************************************
            //CPMS  MAIN LOOPS
            //C     The following lines are executed with every trial!!
            //C     Analyse a big sequence of neighbors ('permutations').
            //C     Compute the penalty and decide whether to accept the new perm
            //C     according to the SOLVER option
            //C-------------------------------------------------------------
            //CPMS---Store two run parameters in case the last temper quench is
            //CPMS   to be "aimed" into the optimum with different parameters
            //CPMS   and the program must reset for another "RPT" run.
            FIXM = COMMOD9.FIXF;
            NABRM = COMMOD9.NABRGEN;

            //Helper.Write("\n  ");
            //if (COMMOD9.PAUSF != 5)
            //{
            //    Console.BackgroundColor = ConsoleColor.Blue;
            //}

            #if FAKE_IJRANKE_DOUBLE
            WritePara.readIJRnk();
            #endif

            //CPMS**START THE OUTER LOOP***************
            for (OUTER = 0; OUTER < (int)COMMOD9.NOUTER; OUTER++)
            {

                //CPMS	check for "AIM"ed tempering
                if ((aimf) && (OUTER == (int)COMMOD9.NOUTER - 1))
                {
                    COMMOD9.FIXF = 0;
                    COMMOD9.NABRGEN = 2;
                }

                //CPMS  write out best solution so far if requested
                if ((stepf) && (COMMOD9.CDF != 1)) Helper.STEPOUT(COMMOD9.BSTPERM);
                if ((stepf) && (COMMOD9.CDF != 1)) Helper.TRAJOUT();

                //CPMS*****START THE INNER LOOP*********
                for (INNER = 0; INNER < (int)COMMOD9.NINNER; INNER++)
                {

                    PCT = PCT - 1;

                    //CPMS-----------------------------------------------------
                    //CPMS       GENERATE A NEIGHBOR AS A CANDIDATE PERMUTATION
                    //CPMS       after saving current state of secondary penalty
                    COMMOD9.TSLST = COMMOD9.TSPEN;
                    Helper.GONABR(ref IRANK, ref JRANK);
            #if FAKE_IJRANKE_DOUBLE
                    COMMOD9.UU = WritePara.FAKE_DOUBLEs[OUTER * (int)COMMOD9.NINNER + INNER];
            #else
                    //CPMS******    This replaces the old calculation of PROB after penalty totalling
                    //CPMS******    It allows NEWPEN to exit the section loop as soon as the critical
                    //CPMS******    penalty size (CRTPEN) is reached.
                    //CPMS******    NEWPEN takes advantage of this, but NWDMPEN does not.....yet
                    //CPMS******    for a riley test, running time drops from 1.133 to 1.117 mins.
                    COMMOD9.UU = COMMOD9.RANDOM.NextDouble();
            #endif

            #if OUTDATA_IJRANK
                    WritePara.writeIJRnk(IRANK, JRANK, COMMOD9.UU);
            #endif

                    //if(COMMOD9.PEN>4000 && COMMOD9.PEN<5000)
                    //    Helper.Write(" T={0} UU={1} Pen={2} ", COMMOD9.T,COMMOD9.UU,COMMOD9.PEN);
                    COMMOD9.CRTPEN = COMMOD9.PEN - (COMMOD9.T * Math.Log(COMMOD9.UU));
                    //if (COMMOD9.PEN > 4000 && COMMOD9.PEN < 5000)
                    //    Helper.Write("CRTPEN={0}\n", COMMOD9.CRTPEN);

                    if (COMMOD9.PENF <= 1)
                    {
                        Helper.NEWPEN(IRANK, JRANK, COMMOD9.PERM, ref COMMOD9.NXTPEN);

                    }
                    else if (COMMOD9.PENF >= 2)

                    {
                        Helper.NWDMPEN(IRANK, JRANK, COMMOD9.PERM, ref COMMOD9.NXTPEN);
                    }

            #if SWT_CHECK_VIA_GETPEN

                    double checkPenalty = 0.0;
                    if (COMMOD9.PENF <= 1)
                    {
                        Helper.GETPEN(COMMOD9.PERM, ref checkPenalty);
                        double delta = Math.Abs(checkPenalty - COMMOD9.NXTPEN);
                        Trace.WriteLineIf(delta > Double.Epsilon, string.Format("{0} - getNwPen={1}, getPen={2}, delta={3}, [COMMOD9.PENF <= 1]", DateTime.Now, COMMOD9.NXTPEN, checkPenalty, delta));
                    }
                    else if (COMMOD9.PENF >= 2)
                    {
                        Helper.GETPEN(COMMOD9.PERM, ref checkPenalty);
                        double delta = Math.Abs(checkPenalty - COMMOD9.NXTPEN);
                        Trace.WriteLineIf(delta > Double.Epsilon, string.Format("{0} - getNwPen={1}, getPen={2}, delta={3}, [COMMOD9.PENF >= 2]", DateTime.Now, COMMOD9.NXTPEN, checkPenalty, delta));
                    }

            #endif

                    DELTA = COMMOD9.NXTPEN - COMMOD9.PEN;

                    //C-----------------------------------------------------------------------
                    //C    DETERMINE WHETHER TO ACCEPT THE NEW PERM OR KEEP THE
                    //C    OLD ONE
                    //C    PEN is the previous penalty
                    //C    NXTPEN is the candidate to replace PEN
                    //C    DELTA is the difference
                    //C-----------------------------------------------------------------------

                    //C-----------------------------------------------------------------------
                    //c          set the flag LAST to 0, saying that the new PERM
                    //C          has not been accepted yet
                    //C
                    //C          IF THE NEW PERM IS BETTER (OR AS GOOD and not "GREEDY"),
                    //C            1. ACCEPT IT, keep PERM, update PEN, TOOPEN and SCTSOL, AND
                    //C            2. SEE IF IT IS BEST SO FAR
                    //C             IF IT IS, UPDATE THE BEST SO FAR (BSTPERM AND BSTPEN)
                    //C		      If a "SQUEEZE" run, accept only if squeeze penalty is not worse
                    //C-----------------------------------------------------------------------

                    LAST = 0;

                    //CPMS       ? replace the next IF with DELTA.LE.0
                    //CPMS       i.e. always accept an equally good move and save the checking time
                    //CPMS       ?? leads to lots of repetitions
                    //CPMS       ??? what is the snag for greedy?
                    //c          /////////////////////////////////////////
                    //CPMS       IF NEW SEQUENCE HAS SAME OR LOWER PENALTY
                    if ((DELTA < 0.0) ||
                        ((DELTA == 0.0) && ((COMMOD9.SOLVEF < 2) ||
                        ((s89f) && (COMMOD9.TSPEN <= COMMOD9.TSBST)) ||
                        ((s67f) && (COMMOD9.SHPEN <= COMMOD9.SHBST)) ||
                        ((s45f) && (COMMOD9.SQPEN <= COMMOD9.SQBST)))))
                    {

                        //HACK:OMIT MANY LINES

                        if (COMMOD9.CTRF == 1)
                        {
                            NCT = NCT + 1;
                            COMMOD9.CTRF = 0;
                        }

                        //update the penalties
                        COMMOD9.PEN = COMMOD9.NXTPEN;
                        COMMOD9.ASPNPEN = COMMOD9.SPANPEN;

                        Helper.DOTOO();

                        if (COMMOD9.PENF < 2)
                        {
                            Helper.CopyArray(COMMOD9.HSCTSOL, ref COMMOD9.SCTSOL);
                        }

                        Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                        LAST = 1;

                        //if this is very best so far
                        if ((COMMOD9.PEN < COMMOD9.BSTPEN) || ((COMMOD9.PEN == COMMOD9.BSTPEN) &&
                            (((s89f) && (COMMOD9.TSPEN < COMMOD9.TSBST)) ||
                            ((s67f) && (COMMOD9.SHPEN < COMMOD9.SHBST)) ||
                            ((s45f) && (COMMOD9.SQPEN < COMMOD9.SQBST)))))
                        {
                            siz = 2;
                            if (COMMOD9.PEN == COMMOD9.BSTPEN) siz = 1;

                            COMMOD9.SQBST = COMMOD9.SQPEN;
                            COMMOD9.SHBST = COMMOD9.SHPEN;
                            COMMOD9.TSBST = COMMOD9.TSPEN;
                            COMMOD9.BSTPEN = COMMOD9.PEN;
                            COMMOD9.NBETR = COMMOD9.NBETR + 1;
                            COMMOD9.BS2PEN = COMMOD9.TOOPEN;
                            COMMOD9.NGTPEN = COMMOD9.NGHPEN;
                            BSTSCOR = (int)COMMOD9.BSTPEN;

                            if ((COMMOD9.KSM > 0.00) && (COMMOD9.PENF < 2)) BSTSCOR = BSTSCOR - (int)COMMOD9.SMPEN;

                            Helper.CopyArray(COMMOD9.PERM, ref COMMOD9.BSTPERM);

                            //HACK:OMIT MANY LINES

                        }
                    }
                    else
                    {
                        //C-----------------------------------------------------------------------
                        //C    LOOK FOR PROBABILISTIC GROUNDS TO ACCEPT
                        //C    EVEN IF THE NEW PERM IS WORSE THAN "PERM",
                        //C    ACCEPT IT WITH PROBABILITY "PROB"
                        //C    PROB replaced by CRTPEN - the critical penalty at PROB
                        //C  //////////////////////////////////////////////////////////////

                        //NOT AN IMPROVEMENT
                        if (COMMOD9.NUDGER)
                        {
                            COMMOD9.NUDGUP = false;
                            COMMOD9.NUDGDN = false;
                        }

                        //CPMS   reject and reset for greedy algorithm
                        //cpms   and shrinker and squeezer and teaser
                        if (algf)
                        {
                            Helper.CopyArray(COMMOD9.LSTPERM, ref COMMOD9.PERM);

                            COMMOD9.TSPEN = COMMOD9.TSLST;

                        }
                        else
                        {
                            //cpms-----------for squeal and anneas and steal--------
                            //cpms	  adjust U downward if 2nd penalty improves
                            //cpms    and up if the 2nd penalty worsens
                            //cpms    adjust according to the new/old ratio squared
                            //cpms	   the adjustments are likely to be small
                            //cpms    but they increase geometrically as the
                            //cpms    impact on the secondary penalty increases
                            //cpms
                            //cpms    the efficiency of the promary search is compromised
                            //cpms    but the secondary penalty is not allowed to
                            //cpms    increase uncontrollably

                            switch (COMMOD9.SOLVEF)
                            {
                                case 1:
                                case 2:
                                case 3:
                                case 4:
                                case 6:
                                case 8:
                                    break;
                                case 5:
                                    if (COMMOD9.SQPEN > 0)
                                        U = U * Math.Pow((COMMOD9.SQPEN / COMMOD9.SQBST), 2);
                                    break;
                                case 7:
                                    if (COMMOD9.SHPEN > 0)
                                        U = U * Math.Pow((COMMOD9.SHPEN / COMMOD9.SHBST), 2);
                                    break;
                                case 9:
                                    if (COMMOD9.TSPEN > 0)
                                        U = U * Math.Pow((COMMOD9.TSPEN / COMMOD9.TSBST), 2);
                                    break;
                            }

                            //cpms-------------------------------------------------

                            if (COMMOD9.NXTPEN < COMMOD9.CRTPEN)
                            {
                                //CPMS    ACCEPT UPHILL STEP
                                //CPMS    and check contraction
                                if (COMMOD9.CTRF == 1)
                                {
                                    NCT = NCT + 1;
                                    COMMOD9.CTRF = 0;
                                }

                                switch (COMMOD9.SOLVEF)
                                {
                                    case 1:
                                    case 2:
                                    case 3:
                                    case 4:
                                    case 6:
                                    case 8:
                                        break;
                                    case 5:
                                        COMMOD9.SQBST = COMMOD9.SQPEN;
                                        break;
                                    case 7:
                                        COMMOD9.SHBST = COMMOD9.SHPEN;
                                        break;
                                    case 9:
                                        COMMOD9.TSBST = COMMOD9.TSPEN;
                                        break;
                                }

                                //update total penalty and secondary penalty
                                COMMOD9.PEN = COMMOD9.NXTPEN;
                                COMMOD9.ASPNPEN = COMMOD9.SPANPEN;

                                Helper.DOTOO();

                                if (COMMOD9.PENF < 2)
                                {
                                    Helper.CopyArray(COMMOD9.HSCTSOL, ref COMMOD9.SCTSOL);
                                }

                                Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                                LAST = 1;

                                //Edit the range lines because bad switch is accepted

                                //CPMS	 Load the EVERYBST array and add points to
                                //CPMS	 the event bathtub - needs to be a separate subroutine
                                if (rlxf)
                                {
                                    FILLBEST(INISCOR, COMMOD9.PEN);
                                    //run through the solution in sequence (EVERYBST cols)
                                    //and enter the penalty for the appropriate
                                    //event (EVERYBST rows), IF the best so far
                                    //i.e. EVERYBST has IROWS order
                                }

                            }
                            else
                            {
                                //C-----------------------------------------------------------------------
                                //CPMS     REJECT UPHILL STEP reset PERM to previous order (any NABRGEN!)
                                //CPMS	   no boxes plotted on the run-time graphic
                                //CPMS     no update to PEN or TOOPEN
                                //CPMS--------------------------------------------------------
                                Helper.CopyArray(COMMOD9.LSTPERM, ref COMMOD9.PERM);
                                COMMOD9.TSPEN = COMMOD9.TSLST;
                                COMMOD9.CTRF = 0;
                            }
                        }
                    }//END if ELSE DELTA>0

                    //cpms  if tempering:
                    if (COMMOD9.SOLVEF == 3) COMMOD9.T = COMMOD9.T * COMMOD9.R;

                    System.Windows.Forms.Application.DoEvents();
                    System.Threading.Thread.Sleep(0);

                }//CPMS*****end of inner loop**************

                //C  lower the temperature and do it again if annealing
                //C  heat to random temperature and quench again if tempering (solvef=3)

                if (COMMOD9.SOLVEF == 3)
                {
                    U = COMMOD9.RANDOM.NextDouble();

                    //c	 PCT/NINNER*NOUTER runs from 1.0 to 0.0
                    //c      IF random number is larger, try again
                    //c      reduces frequency of hot tempers later in run
                    COMMOD9.T = COMMOD9.STARTT * PCT / (COMMOD9.NINNER * COMMOD9.NOUTER) * U;

                    if (COMMOD9.PENF < 2)
                    {
                        Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.PEN);
                    }
                    else if ((COMMOD9.PENF == 5) || (COMMOD9.PENF == 6))
                    {
                        Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.PEN);
                    }
                    else if (COMMOD9.PENF > 1)
                    {
                        Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.PEN);
                    }

                    Helper.CopyArray(COMMOD9.BSTPERM, ref COMMOD9.PERM);
                    Helper.CopyArray(COMMOD9.HSCTSOL, ref COMMOD9.SCTSOL);
                    Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);
                }
                else
                {
                    if (COMMOD9.AUTF == 0) COMMOD9.T = COMMOD9.T * COMMOD9.R;

                    if ((COMMOD9.AUTF == 0) && (COMMOD9.CDF != 1)) Helper.TRAJOUT();
                }

                if (COMMOD9.PAUSF != 5)
                {
                    if (OUTER == COMMOD9.NOUTER - 1)
                    {
                        frm.MSG_SB.Length = 0;
                        frm.MSG_SB.Append("100%");
                        frm.Invalidate();
                        frm.Update();
                    }
                    //else if (OUTER != 0 && (OUTER % ((int)(COMMOD9.NOUTER / 100))) == 0)
                    else if (OUTER != 0)
                    {
                        frm.MSG_SB.Length = 0;
                        frm.MSG_SB.AppendFormat("{0:0.0}%", ((float)(OUTER + 1) / (float)COMMOD9.NOUTER * 100));
                        frm.Invalidate();
                        frm.Update();
                    }
                }

            }//cpms**end of outer loop*********************************************
            #if OUTDATA_IJRANK
            WritePara.closeSW_STATIC();
            #endif

            COMMOD9.AUTPEN = COMMOD9.BSTPEN;
            COMMOD9.NUDGUP = false;
            COMMOD9.NUDGDN = false;

            //CPMS  Now turn to tasks completed only once per run, AFTER annealing
            //cpms-----------------
            //CPMS	restore FIXF and NABRGEN
            COMMOD9.FIXF = FIXM;
            COMMOD9.NABRGEN = NABRM;

            //CPMS-----------------------------------------------------------
            //CPMS     write out last solution tried if requested
            if ((COMMOD9.STEPSOL.Substring(0, 3) == "LST") ||
                (COMMOD9.STEPSOL.Substring(0, 3) == "lst"))
            {
                if (COMMOD9.CDF != 1) Helper.STEPOUT(COMMOD9.LSTPERM);

                if (COMMOD9.CDF != 1) Helper.TRAJOUT();

            }
            //C--------------------------------------------------------------
            //C     save value of PENF
            LAST = COMMOD9.PENF;

            //CPMS  Try to prevent the remaining tasks from
            //c     running during auto-cooling until about to stop
            if ((COMMOD9.PAUSF == 5) && (COMMOD9.NTRIES < COMMOD9.NSTOP - 1))
            {
                COMMOD9.NUDGUP = false;
                COMMOD9.NUDGDN = false;

                goto Label33;
            }

            //C     after all NOUTER*NINNER passes through the loop,
            //CPMS  make sure that HSCTSOL reflects the best solution
            //CPMS  rather than the last tried
            //CPMS  and that HSCTSOL is last set according to correct penalty
            //CPMS  i.e. lvlpen if PENF=1, intpen for all other cases

            if (COMMOD9.PENF == 1)
            {
                COMMOD9.PENF = -1;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.RVLPEN);
                if (LAST == -1) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                COMMOD9.PENF = 0;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.INTPEN);
                if (LAST == 0) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                COMMOD9.PENF = 1;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.LVLPEN);
                if (LAST == 1) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);
            }
            else if (COMMOD9.PENF == 0)
            {
                COMMOD9.PENF = -1;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.RVLPEN);
                if (LAST == -1) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                COMMOD9.PENF = 1;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.LVLPEN);
                if (LAST == 1) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                COMMOD9.PENF = 0;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.INTPEN);
                if (LAST == 0) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);
            }
            else if (COMMOD9.PENF == -1)
            {
                COMMOD9.PENF = 1;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.LVLPEN);
                if (LAST == 1) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                COMMOD9.PENF = 0;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.INTPEN);
                if (LAST == 0) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

                COMMOD9.PENF = -1;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.RVLPEN);
                if (LAST == -1) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

            }

            COMMOD9.NGTPEN = COMMOD9.NGHPEN;
            //CPMS  GETPEN places local horizons to fit the best sequence
            //CPMS  but the final penalty needs to be returned to its
            //CPMS  "democratic" value for an ordinal search

            COMMOD9.PENF = 6;
            if (COMMOD9.FB4LF != 0) Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.SEQPEN);

            COMMOD9.PENF = 5;
            Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.ROYPEN);

            COMMOD9.PENF = 7;
            Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.MOMPEN);
            if (LAST == 7) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

            COMMOD9.PENF = 4;
            Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.RSCPEN);
            if (LAST == 4) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

            COMMOD9.PENF = 3;
            Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.SPTPEN);
            if (LAST == 3) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

            COMMOD9.PENF = 2;
            Helper.DEMPEN(COMMOD9.BSTPERM, ref COMMOD9.ORDPEN);
            if (LAST == 2) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);
            if (LAST == 5) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);
            if ((LAST == 6) && (COMMOD9.FB4LF != 0)) Helper.CopyArray(COMMOD9.COLPEN, ref COMMOD9.SCJPEN);

            //C   SCJPEN now contains the primary section penalties
            //C   But this is pointless for Royal (PENF=5)
            //C   and for Sequel (PENF=6) so
            //C   the ordinal penalty is used instead

            if (LAST > 2)
            {
                COMMOD9.PENF = 0;
                Helper.GETPEN(COMMOD9.BSTPERM, ref COMMOD9.INTPEN);

                //C   COLPEN now contains the ordinal or interval penalties
                //C   whichever contrasts with the primary
            }

            //c  restore PENF
            COMMOD9.PENF = LAST;
            switch (COMMOD9.PENF)
            {
                case -1://eventual
                    COMMOD9.BSTPEN = COMMOD9.RVLPEN;
                    break;
                case 0://interval
                    COMMOD9.BSTPEN = COMMOD9.INTPEN;
                    break;
                case 1://level
                    COMMOD9.BSTPEN = COMMOD9.LVLPEN;
                    break;
                case 2://ordinal
                    COMMOD9.BSTPEN = COMMOD9.ORDPEN;
                    break;
                case 3://spatial
                    COMMOD9.BSTPEN = COMMOD9.SPTPEN;
                    break;
                case 4://rascal/rascer
                    COMMOD9.BSTPEN = COMMOD9.RSCPEN;
                    break;
                case 5://royal (Coex)
                    COMMOD9.BSTPEN = COMMOD9.ROYPEN;
                    break;
                case 6://sequel (Fb4L)
                    if (COMMOD9.FB4LF != 0) COMMOD9.BSTPEN = COMMOD9.SEQPEN;
                    break;
                case 7://momental
                    COMMOD9.BSTPEN = COMMOD9.MOMPEN;
                    break;
            }

            #if WRITERESULT
            WritePara.writeBstPerm();
            Environment.Exit(0);
            #endif

            Label33:

            //HACK:OMIT MANY LINES

            //CPMS-------------------------------------------------------------
            //CPMS  transfer the number of contractions to a common variable
            COMMOD9.CTRF = NCTR;
        }
Exemple #17
0
        //CPMS*****************************************************************
        //CPMC   labels the y-axis for critical scores
        //CPMS*****************************************************************
        private void LBLSCOR(frmCONOP frm, Graphics g, string score, int pnlty)
        {
            COMMOD COMMOD9 = COMMOD.Singleton();
            //scl = 0;
            //top = 0;
            //btm = 50;
            int lft = 100;
            //rit = 0;

            g.DrawString(score.Trim(), frm.MSG_FONT_XS, frm.DW_Brush, (int)((double)lft / 2.5),
                (int)(newy(pnlty)));
        }
Exemple #18
0
        //cpms  fills the EVERYBST array for BESTFILE
        protected void FILLBEST(frmCONOP frm, Graphics g, int ISCOR, double RSCOR)
        {
            int X, Y;

            //cpms   - the penalty for the current solution
            //cpms   - goes into the BESTFILE
            //CPMS*****************************************************
            //CPMS	  run through the solution in sequence (EVERYBST cols)
            //CPMS	  and enter the penalty for the appropriate
            //CPMS	  event (EVERYBST rows), IF the best so far
            //CPMS	  i.e. EVERYBST has IROWS order

            COMMOD COMMOD9 = COMMOD.Singleton();

            for (X = 0; X < COMMOD9.NEVNT; X++)
            {
                COMMOD9.EVERYBST[COMMOD9.PERM[X], X] =
                    Math.Min(COMMOD9.EVERYBST[COMMOD9.PERM[X], X], RSCOR);

                //cpms   update secondary penalty if necessary
                //cpms   SECNDBST stores secondary penalty BEFORE scaling: TO2PEN
                if (COMMOD9.GRID2F == 1)
                {
                    COMMOD9.SECNDBST[COMMOD9.PERM[X], X] =
                        Math.Min(COMMOD9.SECNDBST[COMMOD9.PERM[X], X], COMMOD9.TO2PEN);
                }

                // plot on screen if selected event
                if ((ISCOR > 0) && (COMMOD9.PERM[X] == COMMOD9.XEVNT) && (COMMOD9.RUNGRF == 4))
                {
                    frm.SetColor(10);
                    DRAWSCOR(frm, g, (double)(COMMOD9.NEVNT), (double)(COMMOD9.NEVNT - (X + 1)),
                        (double)ISCOR, RSCOR, 1, 2);
                    frm.SetColor(15);
                }

            }

            if (COMMOD9.VERYBEST == COMMOD9.NXTPEN)
            {
                for (X = 0; X < COMMOD9.NEVNT; X++)
                {
                    for (Y = 0; Y < COMMOD9.NSCT; Y++)
                    {
                        COMMOD9.HSCTRNG[X, Y, 0] =
                            Math.Max(COMMOD9.HSCTRNG[X, Y, 0], COMMOD9.HSCTSOL[X, Y]);

                        COMMOD9.HSCTRNG[X, Y, 1] =
                           Math.Min(COMMOD9.HSCTRNG[X, Y, 1], COMMOD9.HSCTSOL[X, Y]);
                    }
                }
            }
            else if (COMMOD9.VERYBEST > COMMOD9.PEN)
            {
                for (X = 0; X < COMMOD9.NEVNT; X++)
                {
                    for (Y = 0; Y < COMMOD9.NSCT; Y++)
                    {
                        COMMOD9.HSCTRNG[X, Y, 0] = COMMOD9.HSCTSOL[X, Y];
                        COMMOD9.HSCTRNG[X, Y, 1] = COMMOD9.HSCTSOL[X, Y];
                    }
                }

                COMMOD9.VERYBEST = Helper.MinVal(COMMOD9.EVERYBST);

            }
        }
Exemple #19
0
        private void WRITEPEN(frmCONOP frm, Graphics g, Brush brush, int flg)
        {
            COMMOD COMMOD9 = COMMOD.Singleton();
            string ytitle;
            int horiz, vert;
            int scl, top, btm, lft, rit;

            //CPMS-----------------------------------------------
            horiz = 0;
            vert = -90;
            scl = 0;
            top = 0;
            btm = 50;
            lft = 100;
            rit = 0;
            //CPMS-------------------------------------------------------------

            g.TranslateTransform((int)(lft / 9), (int)(COMMOD9.maxy - btm - 125));
            g.RotateTransform(vert);

            if (flg == 1)
            {
                ytitle = "";
                switch (COMMOD9.PENF)
                {
                    case -1:
                        ytitle = "- eventual";
                        break;
                    case 0:
                        ytitle = "- interval";
                        break;
                    case 1:
                        ytitle = "- level";
                        break;
                    case 2:
                        ytitle = "- ordinal";
                        break;
                    case 3:
                        ytitle = "- spatial";
                        break;
                    case 4:
                        ytitle = "- rascal";
                        break;
                    case 5:
                        ytitle = "- royal";
                        break;
                    case 6:
                        ytitle = "- sequel";
                        break;
                    case 7: ytitle = "- momental";
                        break;
                }

                ytitle = "BEST PENALTY" + ytitle;
                g.DrawString(ytitle, frm.MSG_FONT_S, brush, 0, 0);
                g.ResetTransform();
            }
            else if (flg == 2)
            {
                g.DrawString("BEST SUM OF SECONDARY PENALTIES", frm.MSG_FONT_S, brush, 0, 0);
                g.ResetTransform();
            }

            if (COMMOD9.KSM > 0.00)
            {
                brush = frm.MSG_BRUSH_2;
                g.TranslateTransform((int)(lft / 9), (int)(COMMOD9.maxy - btm - 15));
                g.RotateTransform(vert);
                g.DrawString("smoothing - ", frm.MSG_FONT_S, brush, 0, 0);
                g.ResetTransform();
            }
        }
Exemple #20
0
        private void CLIP(frmCONOP frm, Graphics g, int rnki, int rnkj, int rnkt)
        {
            double xrl, yrl;
            //CPMS---------------------------------------------------
            //cpms  rnki -  the former x position
            //cpms  rnkj -  the key to the event number and yrow position
            //cpms  rnkt -  the new x position

            COMMOD COMMOD9 = COMMOD.Singleton();

            xrl = 0.0;
            yrl = 0.0;
            xrl = (double)(rnki + 1) * COMMOD9.XSPAN / (double)COMMOD9.NEVNT;
            yrl = (double)((COMMOD9.IROWS[COMMOD9.LSTPERM[rnkj], 0] + 1) * COMMOD9.YSPAN / COMMOD9.YROWS);

            //int scl = 0;
            int top = 0;
            //int btm = 50;
            int lft = 100;
            //int rit = 0;

            //move to left end (i) of modification
            //line/blank up to right end (j)
            int x1 = lft + (int)xrl;
            xrl = (double)(rnkt + 1) * COMMOD9.XSPAN / (double)COMMOD9.NEVNT;
            int x2 = lft + (int)xrl;
            g.DrawLine(frm.DW_Pen, x1, top + (int)yrl, x2, top + (int)(yrl));
        }
Exemple #21
0
        private void YSCALE(frmCONOP frm, Graphics g, int ybig, int mxx, int mxy, int ytop, int ybtm, int x, int res, bool rndf)
        {
            int div = 0;
            int stp;
            int tck;
            double yreal, fctr;
            string SCORE;

            //C-------------------------------------------------------------------
            //CPMS	  scale line runs from ytop to maxy-ybtm; everywhere at x
            //CPMS	  the biggest x value is xbig (e.g. NEVNT)
            //mxx = mxx  ??<=HXD
            //C---------------------------------------------
            //CPMS	round the top y value

            if (rndf)
            {
                ROUNDUP(ref ybig, res, ref div);
            }

            SCORE = string.Format("{0}", ybig);
            LBLSCOR(frm, g, SCORE, 0);

            //CPMS----------------------------
            //CPMS  Draw the y-axis baseline
            g.DrawLine(frm.DW_Pen, x, ytop, x, mxy - ybtm);

            //CPMS----------------
            //CPMS  Draw the ticks
            if (!rndf)
            {
                div = res;
            }

            if (div > 0)
            {
                tck = 2;
                fctr = (double)(mxy - ybtm - ytop) / (double)(div * 10);
                for (stp = 0; stp <= div * 10; stp++)
                {
                    tck = 2;
                    if (stp % 10 == 0) tck = 6;
                    yreal = (double)(stp) * fctr;
                    g.DrawLine(frm.DW_Pen, x, ytop + (int)(yreal), x - tck, ytop + (int)(yreal));
                }
            }
        }
Exemple #22
0
        /// <summary>
        /// Proxy for frmCONOP implementation
        /// </summary>
        /// <param name="frm"></param>
        public void RunIt(
#if GUIMODE
            frmCONOP frm