Class: PAES_Analysis

Inherits:
Object
  • Object
show all
Defined in:
lib/flukso/plots.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, annotationsfile) ⇒ PAES_Analysis

Returns a new instance of PAES_Analysis.



261
262
263
264
265
266
267
268
# File 'lib/flukso/plots.rb', line 261

def initialize(path, annotationsfile)
  @workingdir=path
  @annotationsfile=annotationsfile
  if @annotationsfile != nil
    @annotations=AnnotationCollection.new(@annotationsfile)
  end
  @runner = RRunner.new(path)
end

Instance Method Details

#appendAnnotations(drawcmd) ⇒ Object

takes a drawcommand as an argument and adds annotations as needed. TODO: Points are not plotted if they are out of the range of the plot - this might be necessary in the future.



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/flukso/plots.rb', line 293

def appendAnnotations(drawcmd)
  if @annotations != nil
    puts "Adding annotations\n#{@annotations.to_s}"
    colors=Array.new()
    labels=Array.new()
    ltyInfo=Array.new()
    pchInfo=Array.new()
    counter=0;
    pointlines=""
    @annotations.each{|a|
      counter+=1;
      colors << counter;
      labels << a.text;
      pointlines+="points(#{a.qt}, #{a.price}, type=\"p\", pty=2, col=#{counter})\n"
      ltyInfo << -1;
      pchInfo << 1;
    }
    cols=arrayToC(colors)
    labelList=arrayToC(labels)
    ltyList=arrayToC(ltyInfo)
    pchList=arrayToC(pchInfo)
    drawcmd+=<<-EOC
      cols=#{cols}
      labels=#{labelList}
      #{pointlines}
      legend("topright", labels, col = cols,
         text.col = "black", lty = #{ltyList}, pch = #{pchList},
         bg = 'gray90')
    EOC
  end
  return drawcmd
end

#arrayToC(input) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/flukso/plots.rb', line 275

def arrayToC(input)
  retval="c("
  input.each{|element|
    if element.instance_of?(String)
      retval += "\"#{element}\","
    else
      retval += "#{element},"
    end
  }
  retval.sub!(/,$/, "");   # delete the last comma
  return retval+")";
end

#plotIntermediate(filename) ⇒ Object



414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/flukso/plots.rb', line 414

def plotIntermediate(filename)
  drawcmd=<<-END_OF_CMD
    plot(data$QT, data$Price, type="b",
      main="Pareto Front (absolute values)",
      xlab="queue time (s)",
      ylab="price"
    )
  END_OF_CMD
  infile=File.join(@workingdir, filename)
  outfile=filename+".eps"
  puts "infile: #{infile}"
  puts "outfile: #{outfile}"
  @runner.execute(infile, outfile, drawcmd)
end

#plotSingleRunObject



269
270
271
272
273
274
# File 'lib/flukso/plots.rb', line 269

def plotSingleRun
  methods.grep(/^plotSingleRun_/){|m|
    self.send(m)
  }
  sleep(1)
end

#plotSingleRun_ParetoSchedules_AbsoluteObject



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/flukso/plots.rb', line 325

def plotSingleRun_ParetoSchedules_Absolute
  basename="absolute-results"
  #main="Pareto Front (absolute values)",
  drawcmd=<<-END_OF_CMD
    plot(data$QT, data$Price, type="b",
      xlab="queue time (s)",
      ylab="price"
    )
  END_OF_CMD
  infile=File.join(@workingdir, basename+".txt")
  outfile=basename+".eps"
  puts "infile: #{infile}"
  puts "outfile: #{outfile}"
  @runner.execute(infile, outfile, drawcmd)
end

#plotSingleRun_ParetoSchedules_IntermediatesObject



403
404
405
406
407
408
409
410
411
412
413
# File 'lib/flukso/plots.rb', line 403

def plotSingleRun_ParetoSchedules_Intermediates
  # Search for all intermediate-* files in the data directory
  Dir.foreach(@workingdir) {|file|
    #puts "checking #{file}"
    if file =~ /^intermediate-/
      if not file =~ /.eps$/
        plotIntermediate(file)
      end
    end
  }
end

#plotSingleRun_ParetoSchedules_RelativeObject



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/flukso/plots.rb', line 340

def plotSingleRun_ParetoSchedules_Relative
  basename="relative-results"
  max_qt_annotation = @annotations.getMaxQT()
  max_price_annotation = @annotations.getMaxPrice()
  min_qt_annotation = @annotations.getMinQT()
  min_price_annotation = @annotations.getMinPrice()
  puts "### Calculated: #{max_qt_annotation}, #{max_price_annotation}"
  #main="Pareto Front (relative values)",
  drawcmd=<<-END_OF_CMD
    max_qt<-max(data$QT, #{max_qt_annotation});
    max_price<-max(data$Price, #{max_price_annotation});
    min_qt<-min(data$QT, #{min_qt_annotation});
    min_price<-min(data$Price, #{min_price_annotation});
    qt_range<-c(min_qt,max_qt);
    price_range<-c(min_price,max_price);
    plot(qt_range, price_range, type="n",
      xlab="queue time (s)",
      ylab="price / second"
    )
    points(data$QT, data$Price, type="b")
  END_OF_CMD
  drawcmd=appendAnnotations(drawcmd)
  infile=File.join(@workingdir, basename+".txt")
  outfile=basename+".eps"
  puts "infile: #{infile}"
  puts "outfile: #{outfile}"
  @runner.execute(infile, outfile, drawcmd)
end

#plotSingleRun_RuntimeObject



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/flukso/plots.rb', line 368

def plotSingleRun_Runtime
  basename="runtime-report"
  drawcmd=<<-END_OF_CMD
    l<-length(data$acc)
    range<-1:l
    plot(range, data$acc, type="n",
      xlab="Iteration (x 1000)",
      ylab="Dominant Solutions"
    )
    points(range, data$acc, type="l", lty=1)
  END_OF_CMD
  infile=File.join(@workingdir, basename+".txt")
  outfile=basename+".eps"
  puts "infile: #{infile}"
  puts "outfile: #{outfile}"
  @runner.execute(infile, outfile, drawcmd)
end

#plotSingleRun_Runtime_DistanceObject



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/flukso/plots.rb', line 385

def plotSingleRun_Runtime_Distance
  basename="runtime-report"
  drawcmd=<<-END_OF_CMD
    l<-length(data$distance)
    range<-1:l
    plot(range, data$distance, type="n",
      xlab="Iteration (x 1000)",
      ylab="Distance"
    )
    points(range, data$distance, type="l", lty=2)
  END_OF_CMD
  infile=File.join(@workingdir, basename+".txt")
  outfile=basename+"-distance.eps"
  puts "infile: #{infile}"
  puts "outfile: #{outfile}"
  @runner.execute(infile, outfile, drawcmd)
end