<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Reading and timing bunches of  SUDOKUs in Optmodel in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-and-timing-bunches-of-SUDOKUs-in-Optmodel/m-p/469632#M2275</link>
    <description>&lt;P&gt;Here's an illustration of looping over solvers, say for your binary formulation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   set SOLVERS = {'clp','milp'};
   num solve_time {INSTANCES, SOLVERS};
   for {instance in INSTANCES} do;
      put instance=;
      instance_this = instance;
      solve with clp;
      solve_time[instance,'clp'] = _OROPTMODEL_NUM_['SOLUTION_TIME'];
      solve with milp;
      solve_time[instance,'milp'] = _OROPTMODEL_NUM_['SOLUTION_TIME'];
   end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And here's an illustration of looping over algorithms for the same solver, LP in this case:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   set ALGORITHMS = {'ds','ps','ns','ip'};
   num solve_time {INSTANCES, ALGORITHMS};
   for {instance in INSTANCES} do;
      put instance=;
      instance_this = instance;
      for {alg in ALGORITHMS} do;
         solve with lp / algorithm=(alg);
         solve_time[instance,alg] = _OROPTMODEL_NUM_['SOLUTION_TIME'];
      end;
   end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please provide the data for the slow instances?&amp;nbsp; What SAS/OR version are you using?&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jun 2018 14:19:15 GMT</pubDate>
    <dc:creator>RobPratt</dc:creator>
    <dc:date>2018-06-12T14:19:15Z</dc:date>
    <item>
      <title>Reading and timing bunches of  SUDOKUs in Optmodel</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-and-timing-bunches-of-SUDOKUs-in-Optmodel/m-p/468407#M2269</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Reading and handling one&amp;nbsp; SUDOKU&amp;nbsp; at a time&amp;nbsp; --&amp;nbsp; no problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I have lists (e.g. 87 records=lines) &amp;nbsp; one SUDOKU ==&amp;nbsp; 1 line&amp;nbsp; - densely packed without spaces.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4...3.......6..8..........1....5..9..8....6...7.2........1.27..5.3....4.9........&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The old SAS code for&amp;nbsp; a quadratic&amp;nbsp; SUDOKU data scheme with spaces :: &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data SUDOKUS.Most_Difficult_1 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; input C1-C9;&lt;BR /&gt;datalines;&lt;BR /&gt;9&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp; .&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The old read data in Optmodel&amp;nbsp; ::&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; read data SUDOKU into [i = _n_] {j in SPALTEN} &amp;lt;SU[i,j] = col("C"||j)&amp;gt; ;&amp;nbsp; /*&amp;nbsp; SPALTEN&amp;nbsp; means&amp;nbsp; COLUMNS */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not aware how the read data has to be modified.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to loop within&amp;nbsp; Optmodel&amp;nbsp; over such collections , produce solutions with various solvers and collect all&amp;nbsp; timing information from&amp;nbsp; SAS Log&amp;nbsp; into&amp;nbsp; SAS datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions how I best handle the technicalities of reading&amp;nbsp; and&amp;nbsp; time collecting ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&amp;nbsp;&amp;nbsp; Odenwald&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 15:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-and-timing-bunches-of-SUDOKUs-in-Optmodel/m-p/468407#M2269</guid>
      <dc:creator>ODENWALD</dc:creator>
      <dc:date>2018-06-07T15:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reading and timing bunches of  SUDOKUs in Optmodel</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-and-timing-bunches-of-SUDOKUs-in-Optmodel/m-p/468527#M2270</link>
      <description>&lt;P&gt;The following code loops over all instances, calling the CLP solver and recording the solution time for each.&amp;nbsp; You could also loop over solvers and record other statistics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data indata;
   input clues $81.;
   datalines;
4...3.......6..8..........1....5..9..8....6...7.2........1.27..5.3....4.9........
..5..7..1.7..9..3....6.......3..1..5.9..8..2.1..2..4....2..6..9....4..8.8..1..5..
;

proc optmodel printlevel=0;
   set INSTANCES;
   str clues {INSTANCES};
   read data indata into INSTANCES=[_N_] clues;
   set ROWS = 1..9;
   set COLS = ROWS; /* Use an alias for convenience and clarity */
   num c {INSTANCES, ROWS, COLS} init .;
   num k;
   for {instance in INSTANCES} do;
      k = 0;
      for {i in ROWS} do;
         for {j in COLS} do;
            k = k + 1;
            c[instance,i,j] = input(char(clues[instance],k),1.);
         end;
      end;
   end;

   /* Declare variables */
   var X {ROWS, COLS} &amp;gt;= 1 &amp;lt;= 9 integer;

   /* Nine row constraints */
   con RowCon {i in ROWS}:
      alldiff({j in COLS} X[i,j]);

   /* Nine column constraints */
   con ColCon {j in COLS}:
      alldiff({i in ROWS} X[i,j]);

   /* Nine 3x3 block constraints */
   con BlockCon {s in 0..2, t in 0..2}:
      alldiff({i in 3*s+1..3*s+3, j in 3*t+1..3*t+3} X[i,j]);

   /* Fix variables to cell values */
   /* X[i,j] = c[i,j] if c[i,j] is not missing */
   num instance_this;
   con FixCon {i in ROWS, j in COLS: c[instance_this,i,j] ne .}:
      X[i,j] = c[instance_this,i,j];

   num solve_time {INSTANCES};
   for {instance in INSTANCES} do;
      put instance=;
      instance_this = instance;
      solve;
      print X;
      solve_time[instance] = _OROPTMODEL_NUM_['SOLUTION_TIME'];
   end;
   print solve_time;

   create data outdata from [instance] solve_time;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jun 2018 20:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-and-timing-bunches-of-SUDOKUs-in-Optmodel/m-p/468527#M2270</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2018-06-07T20:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reading and timing bunches of  SUDOKUs in Optmodel</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-and-timing-bunches-of-SUDOKUs-in-Optmodel/m-p/469563#M2274</link>
      <description>&lt;P&gt;Hi Rob :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Super !&amp;nbsp; Worked technically like a charm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you add some details w.r.t.&amp;nbsp; looping over&amp;nbsp; solvers&amp;nbsp; etc&amp;nbsp; ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I noted some effects you are probably aware of with the way of setting up the model :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The OPTMODEL presolver is disabled for problems with predicates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Running&amp;nbsp;&amp;nbsp; 1465&amp;nbsp; SUDOKUs&amp;nbsp; there was a huge variation (solving time going up to&amp;nbsp; 16, 19, 99!&amp;nbsp; secs&amp;nbsp; and completely effecting the&amp;nbsp; average to the negative ::&lt;/P&gt;&lt;P&gt;on a slow notebook&amp;nbsp; :&amp;nbsp; average =&amp;nbsp; 0.2278&amp;nbsp; median = 0.016&amp;nbsp; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the&amp;nbsp; trivariate&amp;nbsp; binary variables approach&amp;nbsp; average(MILP)&amp;nbsp; =&amp;nbsp; 0.013&amp;nbsp; and&amp;nbsp; average(CLP) =&amp;nbsp; 0.014&amp;nbsp;&amp;nbsp; over the same set of puzzles.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.................&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Odenwald&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 10:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-and-timing-bunches-of-SUDOKUs-in-Optmodel/m-p/469563#M2274</guid>
      <dc:creator>ODENWALD</dc:creator>
      <dc:date>2018-06-12T10:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Reading and timing bunches of  SUDOKUs in Optmodel</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Reading-and-timing-bunches-of-SUDOKUs-in-Optmodel/m-p/469632#M2275</link>
      <description>&lt;P&gt;Here's an illustration of looping over solvers, say for your binary formulation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   set SOLVERS = {'clp','milp'};
   num solve_time {INSTANCES, SOLVERS};
   for {instance in INSTANCES} do;
      put instance=;
      instance_this = instance;
      solve with clp;
      solve_time[instance,'clp'] = _OROPTMODEL_NUM_['SOLUTION_TIME'];
      solve with milp;
      solve_time[instance,'milp'] = _OROPTMODEL_NUM_['SOLUTION_TIME'];
   end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And here's an illustration of looping over algorithms for the same solver, LP in this case:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   set ALGORITHMS = {'ds','ps','ns','ip'};
   num solve_time {INSTANCES, ALGORITHMS};
   for {instance in INSTANCES} do;
      put instance=;
      instance_this = instance;
      for {alg in ALGORITHMS} do;
         solve with lp / algorithm=(alg);
         solve_time[instance,alg] = _OROPTMODEL_NUM_['SOLUTION_TIME'];
      end;
   end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please provide the data for the slow instances?&amp;nbsp; What SAS/OR version are you using?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 14:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Reading-and-timing-bunches-of-SUDOKUs-in-Optmodel/m-p/469632#M2275</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2018-06-12T14:19:15Z</dc:date>
    </item>
  </channel>
</rss>

