Share

Multiple Scenarios, Single Run (MSSR)

time*treat's avatar - radar

Part 1 

So, you have a system but you don't know which set of limits/parameters are "best" to use. You are tired of changing the limits, running the code, repeating... ad infinitum. Or, maybe you have a better use for your time than watching your screen. I will outline/describe a way to, within limits, let you test multiple scenarios for your system.

Your basic programming tools will be for-next loops and arrays/matricies. You will also need 1 sheet of paper. The paper will help you visualize better.

For simplicity, we'll test 4 parameter sets, using only integers. On paper, create 4 columns, one for each set/scenario. Each row will represent a parameter; like start point, end point, step value, or static value, etc.

Here is the pretend system: Hot-Warm-Cool-Cold ~ 25choose4 Lotto 
I want to play/wheel the most frequent 5 numbers from the last 10 drawings.
No. Wait. Make that - most frequent 7 numbers from 11 to 20 drawings ago.
Or how about the most frequent 9 numbers from the last 20 drawings?
Even more esoteric - most frequent 9 numbers, most recent 20 drawings, but ONLY the odd draws. Hmm... let's do them all.

This goes on your paper:

param col1 col2 col3 col4 
mst frq
57
start11111
stop10202020
step1112

Generally, the more scenarios you want to test, the more columns.
The more parameters you want to include, the more rows.
Since this is just proof-of-concept, I'm leaving out a lot of complexity.

In Part 2, I will go through the steps of putting this array to work, so you don't have to.

~ End of part 1 ~ 

 

truecritic's avatar - PirateTreasure

Looks good so far.

time*treat's avatar - radar

Part 2

This is where we turn the array into a workhorse. Each language/app has a way of storing data. It may be a data file, a location on a spreadsheet, those read-data statements in some of the older flavors of BASIC, or something else.

Declare a variable for each parameter, in this case, you will declare 4 names (best_ranks, start_point, end_point, step_value).

The next step is to create an array at the top of the code. In this case, it will be a 4rows-by-4cols array. The values that go in it will be the same ones that are on the paper. 

your pseudo-code will look like this
(I'm using BASIC because it's easiest to understand)
(anything inside 'single quotes' is a comment)

for column = 1 to number_of_columns 'in this case, number_of_columns = 4'
    'load parameters'
    best_ranks = array(1,column)
    start_point = array(2,column)
    end_point = array(3,column)
    step_value = array(4, column)

    'default step value is 1, when "step x" is left out'
    for position = start_value to end_value step step_value
        'here your code does its normal "thing" with the values it picked up in column'
    next position

    'collect data for best ranks'
    'here you would either print a report or send your output'
    'to "output sheet" #(col) <-- get it? each data result gets its own output page  '
    'you could even store it as a little data file e.g. dataset_col1, dataset_col2, etc.'
    'assigning the column number to part of a string name'
next column 'gets the next column of data limits to test'

~end of p-code~ 

When you are done, you have 4 reports you can compare. You only had to do a little additional work of setting up the array and deciding how/where you wanted the output.

I have mini macro for the eXceL crowd. It just shows you can lift separate data sets, but does so based on active cell. It was what I was writing when I hit upon the above idea. If there is demand, I will post it as a part 3.

~ End of part 2 ~

 

truecritic's avatar - PirateTreasure

If I get it so far, for GW BASIC, I would first set up my data file consisting of say, 10 pick 3 numbers and this would be the code from there?

10 COLOR 14,9: CLS: CLEAR
20 DIM BESTRANK(10), STARTPOINT(10), ENDPOINT(10), STEPVALUE(10)
30 PICKS=10
40 OPEN "10.DAT" FOR INPUT AS #1
Then on to FOR/NEXT Loops or whatever.

Or do you really need 2 dimensional arrays?

time*treat's avatar - radar

truecritic,

If you wanted to do just 1 scenario, you could do it your way. The reason I use a 2-D array is to let you do multiple scenarios at once...well just running the code once. The 2-D arrays job is to store all of the limit sets. The (first) for-next loop picks up each limit-set (one at a time) and processes it.

This may be harder in a language that uses line numbers.
I posted it for people who already had something up and running, but were fiddling with the parameters. The idea was to test something they already had without having to rewrite a major portion of their original code. If you are writing something (in a line-number language) from scratch, you may be ok though.

By the way, if you have really complex ideas, you could use 3-or-more D arrays.
You may need a few more sheets of paper, though. Cool

truecritic's avatar - PirateTreasure

Hehe...my brain no longer functions in the complex mode! Wink

Avatar

time*treat said:

 "I have mini macro for the eXceL crowd. It just shows you can lift separate data sets, but does so based on active cell. It was what I was writing when I hit upon the above idea. If there is demand, I will post it as a part 3."

 

Thank you for taking the time to share this with us, time*treat.  I would be interested in your Excel mini macro. 

 

time*treat's avatar - radar

Part 3: mini macro

This section will demonstrate a manual version of what was described in parts 1 & 2. It will "pick up" data from one place and copy it to another. It's just for visualization. Of course, you could do much more with it.
step 1: open a new workbook
step 2: tools --> macro --> vis bas editor

(in the vb editor)
step 3: insert --> module
step 4: type "sub " and some name for the macro
step 5: (Enter/Return)

Now in the VBE you will have:

Sub some__name()

End Sub

(back on the spreadsheet)
step 6: tools --> macro --> macros --> options
you will be able to assign a shortcut key in the little box.
step 7: put "Q" in the little box, leave out the ""
step 8: press "ok"
step 9: close the "Macro" dialog box
step 10: In row 1, put something in the first 5 columns. Colors, days of the week, whatever.
step 11: In rows 3-12, in each of the first 5 cols, put other stuff, e.g. random numbers, text, whatever.
step 12: Go back to the "empty" macro in the VBE
step 13: Between "sub" and "end sub" C & P the following:
'--------------------------'
    Dim row As Integer, col As Integer
    If Application.ActiveCell.row = 1 Then
      If Application.ActiveCell.Column < 6 Then
        col = Application.ActiveCell.Column
        Cells(5, 7).Value = Cells(5, col).Value
        For row = 1 To 12
          Cells(row, 7).Value = Cells(row, col).Value
        Next row
      End If
    End If
'--------------------------'
(only 10 lines of code. I said it was 'mini')
step 14: go back to spreadsheet
step 15: select any cell in row 1, between cols 1 - 5
step 16: press ctrl+q
step 17: select any other cell
step 18: press ctrl+q, to see the difference.

 

time*treat's avatar - radar

~ skip counter, macro style~

The setup
filename: skip__count.xls
tabname: Pick3
in row 1:
col 1: date
col 2: num
col 3: ~
col 4: skip

row 2: ---
row 3: first line of data (e.g. jan 1)
row 4: next line of data (e.g. jan 2)

no blank lines between data

under last line, col 1: EOF

(skip is 1 less than drawing difference.
IOW, if a number comes out 2 days in a row, the skip is "0")
Thus: 

 r/c
 1 datenum skip 
 2------  --- 
 3 jan 1, 1990522   
 4 jan 2, 1990
282   
 x dec 31, 1999
458   
 x+1 EOF   

the function & macro can go in the same vb module 

1 function (remember this?) ...

Function lowform_3(three_digit)
      Dim channel() As Integer
      Dim slot() As Integer
      Dim num As Integer, pos As Integer
      Dim c0, c1, c2, c3
     
      c0 = three_digit
      c1 = Int(c0 / 100)
      c2 = Int((c0 Mod 100) / 10)
      c3 = c0 Mod 10
      ReDim channel(9)
      ReDim slot(3)
      channel(c1) = channel(c1) + 1
      channel(c2) = channel(c2) + 1
      channel(c3) = channel(c3) + 1
      pos = 1
      For num = 0 To 9
          While channel(num) > 0
            slot(pos) = num
            channel(num) = channel(num) - 1
            pos = pos + 1
          Wend
      Next num
      lowform_3 = slot(1) * 100 + slot(2) * 10  + slot(3)
    End Function

 

Plus 1 macro ...

    Sub skip__counter()
      Dim P3 As Object
      Set P3 = Workbooks("skip__count.xls").Sheets("Pick3")
      Dim in__col As Integer, out__col As Integer
      Dim in__row As Integer, test__row As Integer
      Dim cur__num As Integer, test__num As Integer
      Dim match__flag As Boolean
      Const top__row As Integer = 3
     
      in__col = 2
      out__col = 4
      in__row = 4
     
      While P3.Cells(in__row, 1).Value <> "EOF"
        match__flag = False
        P3.Cells(in__row, 1).Select
        cur__num = lowform_3(P3.Cells(in__row, in__col).Value)
       
        For test__row = in__row - 1 To top__row Step -1
          test__num = lowform_3(P3.Cells(test__row, in__col).Value)
          If cur__num = test__num Then
            P3.Cells(in__row, out__col).Value = in__row - test__row - 1
            P3.Cells(in__row, out__col).NumberFormat = "#,##0"
            match__flag = True
            Exit For
          End If
        Next test__row
       
        If match__flag = False Then
          P3.Cells(in__row, out__col).Value = "no repeat"
        End If
       
        in__row = in__row + 1
      Wend
      P3.Cells.EntireColumn.AutoFit
    End Sub
 

~Please place tips in the jar Cool~

 

 

TopEnd of thread (1 page)

Welcome Guest

Your last visit: Sat, Oct 31, 2020, 5:23 am

Log In

Log InCancel

Forgot your username?

Forgot your password?