示例#1
0
    def transition(self, tprob):

        """
        
        transition function
        
            randomly sample a number from uniform distribution


        """

        tprob_range = cdf(tprob)

        rprob = np.random.uniform()

        for i in xrange(len(tprob)):
            
            if tprob_range[i] < rprob and rprob < tprob_range[i+1]:
                
                return i # return which action to run
示例#2
0
import argparse
import os
import json

import utils

if __name__ == '__main__':
    gaps = []
    for group in utils.listGroups():
        for fn in utils.listGroupInstances(group):
            print(fn)
            topology = fn.split('.')[0]
            data = utils.read_data(group, 'cycleCoverGreedyRounding', topology)
            assert data != None, topology
            lb = float(data['lpBound'])
            greedy = int(data['greedyCoverSize'])
            gap = (greedy - lb) / lb
            if gap > 0.98:
                print(greedy, lb, topology)
                exit(0)
            gaps.append(gap)
    print(max(gaps))
    x, y = utils.cdf(gaps, 0.1)
    plt.plot(x, y)
    plt.xlabel("Gap between greedy solution and lower bound")
    plt.ylabel("Percentage of topologies")
    plt.savefig('../data/plot/minCycleCover_gapcdf.eps',
                format='eps',
                dpi=600,
                bbox_inches='tight')
示例#3
0
import numpy as np
from pylab import *
import argparse
import os
import json

import utils

if __name__ == '__main__':
    runtime = []
    for group in utils.listGroups():
        for fn in utils.listGroupInstances(group):
            print(fn)
            topology = fn.split('.')[0]
            data = utils.read_data(group, 'maxEDPMip', topology)
            assert data != None, topology
            res = data['pairResults']
            for r in res:
                runtime.append(float(r['runtime']) / 1e9)
    x, y = utils.cdf(runtime, 0.01)
    ax = plt.subplot()
    ax.set_xscale("log")
    plot(x, y)
    plt.xlabel("Runtime in seconds")
    plt.ylabel("Percentage of topologies")
    plt.savefig('../data/plot/maxEDPMip_runtime.eps',
                format='eps',
                dpi=600,
                bbox_inches='tight')
示例#4
0
import numpy as np
from pylab import *
import argparse
import os
import json

import utils

if __name__ == '__main__':
    x = []
    for group in utils.listGroups():
        for fn in utils.listGroupInstances(group):
            topology = fn.split('.')[0]
            data = utils.read_data(group, 'diamDeg', topology)
            assert data != None, topology
            v = int(data['edgeDiam'])
            x.append(v)
            print(v)
    #x = utils.data_to_bar(x)
    x.sort()
    print(x)
    x, y = utils.cdf(x, 1)
    plt.plot(x, y)
    plt.show()
    #groups = [ str(i) for i in range(len(x)) ]
    #utils.make_g_barplot([x], groups, ['diameter'], ['#3CAEA3'], 'diameter', 'percentage of topologies', '', '../data/plot/diameter.eps', 5)
示例#5
0
import numpy as np
from pylab import *
import argparse
import os
import json

import utils

if __name__ == '__main__':
    igp = []
    for group in utils.listGroups():
        for fn in utils.listGroupInstances(group):
            print(fn)
            topology = fn.split('.')[0]
            data = utils.read_data(group, 'primeIGP', topology)
            assert data != None, topology
            igp.append(float(data['igp']))
    print(igp)
    x, y = utils.cdf(igp, 1)
    ax = plt.subplot()
    plt.axvline(x=65535, color='k', linestyle='--')
    plot(x, y)
    plt.xlabel("Maximum IGP weight")
    plt.ylabel("Percentage of topologies")
    plt.savefig('../data/plot/primeIGP.eps',
                format='eps',
                dpi=600,
                bbox_inches='tight')
    print(utils.cdf_percentage(x, y, 65535))
示例#6
0
  runtime1 = [ ]
  runtime2 = [ ]
  ratio = [ ]
  skip = [ ]
  for group in utils.listGroups():
    for fn in utils.listGroupInstances(group):
      print(fn)
      topology = fn.split('.')[0]
      data = utils.read_data(group, 'forwPrecompute', topology)
      assert data != None, topology
      t_filter = data['filter']
      t_toposort = data['toposort']
      ratio.append(t_filter / t_toposort)
      runtime1.append(t_filter / 1e9)
      runtime2.append(t_toposort / 1e9)
  x, y = utils.cdf(runtime1, 0.01)
  ax = plt.subplot()
  ax.set_xscale("log")
  plot(x, y, label='filter')
  x, y = utils.cdf(runtime2, 0.01)
  plot(x, y, label='toposort')
  ax.legend()
  """
  x, y = utils.cdf(ratio, 0.01)
  plot(x, y, label='toposort')
  """
  
  plt.xlabel("Runtime in seconds")
  plt.ylabel("Percentage of topologies")
  plt.savefig('../data/plot/precompute_forw_runtime.eps', format='eps', dpi=600, bbox_inches='tight')  
示例#7
0
import numpy as np
from pylab import *
import argparse
import os
import json

import utils

if __name__ == '__main__':
    times = []
    for group in utils.listGroups():
        for fn in utils.listGroupInstances(group):
            print(fn)
            topology = fn.split('.')[0]
            data = utils.read_data(group, 'cycleCoverGreedyRounding', topology)
            assert data != None, topology
            t = int(data['runtime'])
            times.append(t / 1e9 / 60)
    print(len(times))
    print(max(times))

    x, y = utils.cdf(times, 0.1)
    plt.plot(x, y)
    plt.xlabel("Runtime of the cycle cover CG algorithm (in minutes)")
    plt.ylabel("Percentage of topologies")
    plt.savefig('../data/plot/minCycleCover_runtime_cdf.eps',
                format='eps',
                dpi=600,
                bbox_inches='tight')
示例#8
0
    if V <= 20:
        return 'small'
    elif V <= 50:
        return 'medium'
    elif V <= 100:
        return 'large'
    else:
        return 'huge'


if __name__ == '__main__':
    den = []
    for group in utils.listGroups():
        for fn in utils.listGroupInstances(group):
            print(group, fn)
            name = fn.split('.')[0]
            data = utils.read_data(group, 'Analysis', name)
            V = float(data['V'])
            E = float(data['E'])
            den.append(E / (V * (V - 1)))
    x, y = utils.cdf(den, 0.01)
    plot(x, y, label='Edge density')
    plt.xticks([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1])
    plt.xlabel("Edge density")
    plt.ylabel("Percentage of topologies")
    plt.legend()
    plt.savefig('../data/plot/edge_density.eps',
                format='eps',
                dpi=600,
                bbox_inches='tight')
示例#9
0
import utils


def read_data(group, topology, experiment):
    return json.load(
        open('../data/results/' + group + '/' + experiment + '/' + topology +
             '.res'))


if __name__ == '__main__':
    experiment = 'nonSP'
    ratios = {}
    ratios = []
    for group in utils.listGroups():
        for fn in utils.listGroupInstances(group):
            print(group, fn)
            name = fn.split('.')[0]
            data = read_data(group, name, experiment)
            ratio = 100 * float(data['nonSP']) / float(data['E'])
            ratios.append(ratio)
    x, y = utils.cdf(ratios, 0.01)
    fig, ax = plt.subplots()
    plt.plot(x, y)
    ax.set_title("CDF of edges that do not belong to any shortest path")
    plt.xlabel("Percentage of edges")
    plt.ylabel("Percentage of topologies")
    plt.savefig('../data/plot/nonSP.eps',
                format='eps',
                dpi=600,
                bbox_inches='tight')
示例#10
0
            if data != None:
                for r in data['pairResults']:
                    rt_mip = float(r['mip_runtime'])
                    rt_ded = float(r['dedicated_runtime'])
                    rat_3.append(f(float(rt_mip), float(rt_ded)))
                    p_3_mip.append(f(rt_mip, rt_ded))
                    p_3_ded.append(f(rt_ded, rt_mip))

            data = utils.read_data(group, 'SR2EDP_4', topology)
            if data != None:
                for r in data['pairResults']:
                    rt_mip = r['mip_runtime']
                    rt_ded = r['dedicated_runtime']
                    rat_4.append(f(float(rt_mip), float(rt_ded)))
    plt.axvline(x=1, color='k', linestyle='--')
    x, y = utils.cdf(p_3_mip, 0.1)
    p_3_mip.sort()
    plt.plot(x, y, label="mip")
    x, y = utils.cdf(p_3_ded, 0.1)
    p_3_ded.sort()
    plt.plot(x, y, label="dedicated")
    plt.legend()
    plt.xticks([1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55])
    plt.ylim(0, 110)
    plt.xlabel("Ratio between algorithm runtime and minimum runtime (k=3)")
    plt.ylabel("Percentage of topologies")
    plt.savefig('../data/plot/2SREDP_3.eps',
                format='eps',
                dpi=600,
                bbox_inches='tight')
示例#11
0
      data = utils.read_data(group, 'minCover', topology)
      assert data != None, topology
      
      lb1 = float(data['lpBound'])
      init = int(data['initialCoverSize'])
      bound_by_size.append((V + E, lb1))
      init_by_size.append((V + E, init))

      data = utils.read_data(group, 'minCover_complete', topology)
      assert data != None, topology

      lb2 = float(data['lpBound'])
      init = int(data['initialCoverSize'])
      bound_by_size_complete.append((V + E, lb2))
      init_by_size_complete.append((V + E, init))
      lb_ratios.append(lb1 / lb2)

  fig = plt.figure()
  ax = fig.add_subplot(111)
  ax.text(0.3, 90, r'original igp is better', fontsize=12)
  ax.text(1.1, 10, r'complete igp is better', fontsize=12)

  plt.axvline(x = 1, color = 'k', linestyle='--')
  x, y = utils.cdf(lb_ratios, 0.01)


  plt.plot(x, y)
 
  plt.savefig('../data/plot/minCycleCover_lbRatio_cdf.eps', format='eps', dpi=600, bbox_inches='tight')  

示例#12
0
import numpy as np
from pylab import *
import argparse
import os
import json

import utils

if __name__ == '__main__':
    it = []
    for group in utils.listGroups():
        for fn in utils.listGroupInstances(group):
            print(fn)
            topology = fn.split('.')[0]
            data = utils.read_data(group, 'randomIGP', topology)
            assert data != None, topology
            it.append(float(data['averageIter']))
    x, y = utils.cdf(it, 1)
    ax = plt.subplot()
    plot(x, y)
    plt.xlabel("Number of iterations")
    plt.ylabel("Percentage of topologies")
    plt.savefig('../data/plot/randomIGP.eps',
                format='eps',
                dpi=600,
                bbox_inches='tight')
示例#13
0
import numpy as np
from pylab import *
import argparse
import os
import json

import utils

if __name__ == '__main__':
    gap = []
    for group in utils.listGroups():
        for fn in utils.listGroupInstances(group):
            print(fn)
            topology = fn.split('.')[0]
            data = utils.read_data(group, 'cycleCoverGreedyRounding', topology)
            assert data != None, topology
            lb = float(data['lpBound'])
            greedy = int(data['greedyCoverSize'])
            gap.append(100 * (greedy - lb) / lb)
    print(gap)
    x, y = utils.cdf(gap, 0.1)
    plt.plot(x, y)
    plt.xlabel("Difference between greedy solution and lower bound")
    plt.ylabel("Percentage of topologies")
    plt.savefig('../data/plot/minCycleCover_gap.eps',
                format='eps',
                dpi=600,
                bbox_inches='tight')
示例#14
0
文件: analysis.py 项目: yunoac/thesis
     small += 1
   elif v <= 50:
     medium += 1
   elif v <= 100:
     large += 1
   else:
     huge += 1
 print(100 * small / n, 100 * medium / n, 100 * large / n, 100 * huge / n)
 print(min(V))
 print(max(V))
 print(min(E))
 print(max(E))
 nonSP /= n
 ECMP /= n
 print('nonSP: ', 100 * nonSP, 'ECMP: ', 100 * ECMP)
 x, y = utils.cdf(sp_count, 1)
 """
 plot(x, y)
 ax = plt.subplot()
 ax.set_xscale("log")
 plt.xlabel("Number of shortest paths")
 plt.ylabel("Percentage of pairs")
 plt.savefig('../data/plot/spCount.eps', format='eps', dpi=600, bbox_inches='tight')  
 """
 x, y = utils.cdf(min_cut, 1)
 print(max(min_cut))
 plot(x, y, label='Min-cut')
 #plt.xticks([1, 2, 3, 4, 5, 6, 7, 8, 10, 46], [1, 2, 3, 4, 5, 6, 7, 8, 10, 46])
 #plt.xlabel("Minimum cut")
 #plt.ylabel("Percentage of pairs")
 #plt.savefig('../data/plot/minCuts.eps', format='eps', dpi=600, bbox_inches='tight')