Example #1
0
def knapsackplot(prob, length, fname):
    Y = []
    Y2 = []
    for i in xrange(2**length):
        kstr = qopt.int2bin(i, length)  # + '1' * (length - 20)
        #prob.repair(kstr)
        #print kstr
        e = prob.evaluate2(kstr)
        #print e
        # e = prob.evaluate(kstr)
        if True:  # e[0] <= prob.capacity:
            Y.append(e[1])
            Y2.append(e[0])
    Yg = []
    for g in grouper(2**length / 1024, Y):
        Yg.append(max(g))
    Y = Yg
    Y2g = []
    for g in grouper(2**length / 1024, Y2):
        Y2g.append(numpy.average(g))
    Y2 = Y2g
    fig1 = pylab.figure()
    ax1 = fig1.add_subplot(111)
    # s = sorted(Y)
    # print s[-10:]
    price = ax1.plot(Y, '.-')
    pylab.xlim([0, len(Y)])
    #pylab.ylim([-50,130])
    #pylab.ylim([520,521])
    pylab.ylabel(u'Wartość rozwiązania $f(x)$')
    ax1.grid(True)
    ax2 = fig1.add_subplot(111, sharex=ax1, frameon=False)
    ax2.yaxis.tick_right()
    ax2.yaxis.set_label_position('right')
    weight = ax2.plot(Y2, 'r')
    ax2.plot([0, len(Y2)], [prob.capacity, prob.capacity], 'r', linewidth=3)
    pylab.ylim([min(Y2), max(Y)])
    pylab.xlim([0, len(Y)])
    pylab.xticks((0, len(Y) / 4, len(Y) / 2, len(Y) / 4 * 3., len(Y)),
                 ('000...0', '010...0', '100...0', '110...0', '111...1'))
    pylab.ylabel(u'Waga rozwiązania')
    pylab.xlabel(u'Przestrzeń rozwiązań $X$')
    pylab.title(u'Problem plecakowy')
    pylab.legend((price[0], weight[0]),
                 (u'Wartość rozwiązania', u'Waga rozwiązania'),
                 loc='upper left',
                 shadow=True,
                 fancybox=True,
                 borderpad=0.3)
    pylab.savefig(fname, bbox_inches='tight')
Example #2
0
def satplot(prob, length, fname):
    global Y
    Y = []
    for i in xrange(2**length):
        kstr = qopt.int2bin(i, length)  # + '0' * (length - 14)
        Y.append(prob.evaluate(kstr))
    Yg = []
    for g in grouper(2**length / 1024, Y):
        Yg.append(max(g))
    Y = Yg
    pylab.figure()
    pylab.plot(Y)
    pylab.xlim([0, len(Y)])
    pylab.grid(True)
    pylab.yticks(numpy.arange(pylab.ylim()[0] + 1, pylab.ylim()[1] + 1))
    pylab.xticks((0, len(Y) / 4, len(Y) / 2, len(Y) / 4 * 3., len(Y)),
                 ('000...0', '010...0', '100...0', '110...0', '111...1'))
    pylab.ylabel(u'Liczba prawdziwych klauzul')
    pylab.xlabel(u'Przestrzeń rozwiązań $X$')
    pylab.savefig(fname, bbox_inches='tight')
Example #3
0
schema = '10100**********'
schema = '1*1001*********'
schema = '1010***********'
schema = '10010**********'
#schema = '1000*1*********'
#schema = '1000***********'

schema = '01001**********'
schema = '01*01**'
schema = '*1*0***'

coverage = []
X = pylab.linspace(0, 200, 200)

for i in xrange(2**len(schema)):
    chromo = qopt.int2bin(i, len(schema))
    coverage.append(-int(matches(chromo, schema)))

#angles=[0, 60, 45, 45, 45, 45, 45, 45]
#angles=[0, 90, 30, 45, 45, 45, 45, 45]
#angles=[45, 45, 30, 30, 45, 70, 45, 45]
#angles=[0, 90, 45, 45]

#angles=[(0,1,0,.5), (0.8,.4,.8,.2), (.5,.6,.7,.8)]

#angles=[0, 90, 30, 0, 90, 90,45,45,45,45,45,45,45,45,45]
#angles=[0, 90, 30, 30, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45]
#angles=[45, 45, 25, 10, 45, 45, 30, 45, 45, 45, 45, 45, 45, 45, 45]
angles = [30, 80, 35, 35]
#angles=[0, 45,45,45,45,45,45,45,45,45,45,45,45,45,45]
#angles=[0,0,0,0]
Example #4
0
#schema = '01*01**********'
schema = '*1*0***********'

schema = '0*110**********'

schema = '****0'
schema = '***10'
schema = '*1*0****'
#schema = '01*01***'
#schema = '01001***'

coverage = []
X = pylab.linspace(0, 200, 200)

for i in xrange(2**len(schema)):
    chromo = qopt.int2bin(i, len(schema))
    coverage.append(-int(matches(chromo, schema)))

angles = [0, 60, 45, 45, 45, 45, 45, 45]
angles = [0, 90, 30, 45, 45, 45, 45, 45]
angles = [45, 45, 30, 30, 45, 70, 45, 45]
angles = [0, 90, 45, 45]

#angles=[(0,1,0,.5), (0.8,.4,.8,.2), (.5,.6,.7,.8)]

#angles=[0, 90, 30, 0, 90, 90,45,45,45,45,45,45,45,45,45]
#angles=[0, 90, 30, 30, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45]
#angles=[45, 45, 25, 10, 45, 45, 30, 45, 45, 45, 45, 45, 45, 45, 45]
#angles=[25, 60, 35, 35, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45]
#angles=[0, 45,45,45,45,45,45,45,45,45,45,45,45,45,45]
#angles=[0,45, 45]
Example #5
0
k15 = qopt.problems._knapsack.KnapsackProblem(
    '../../problems/knapsack/knapsack-15.txt')
k20 = qopt.problems._knapsack.KnapsackProblem(
    '../../problems/knapsack/knapsack-20.txt')
k25 = qopt.problems._knapsack.KnapsackProblem(
    '../../problems/knapsack/knapsack-25.txt')
sat = qopt.problems._sat.SatProblem('../../problems/sat/random-20.cnf')
#fun = qopt.problems.func1d.f2
fun = sat

f = open(qopt.path('data/sat-20-best'))

if True:
    lines = f.readlines()
    numbers = [int(line) for line in lines]
    cs = [qopt.int2bin(n, 20) for n in numbers]
    #bla=[(c,fun.evaluate(fun.getx(c))) for c in cs]
    bla = [(c, fun.evaluate(c)) for c in cs]
    bla2 = sorted(bla, lambda x, y: cmp(x[1], y[1]))
    for lin in bla2:
        print lin
    sys.exit(0)

# knapsack
lines = f.readlines()
numbers = [int(line) for line in lines]
cs = [qopt.int2bin(n, 20) for n in numbers]

bla = []
for c in cs:
    s = '%s' % c
Example #6
0
schema = '01*011*********'
schema = '10100**********'
schema = '1*1001*********'
schema = '1010***********'
schema = '10010**********'
#schema = '1000*1*********'
#schema = '1000***********'

schema = '01001**********'
schema = '01*01**********'

coverage = []
X = pylab.linspace(0, 200, 200)

for i in xrange(2**len(schema)):
    chromo = qopt.int2bin(i, len(schema))
    coverage.append(-int(matches(chromo, schema)))

angles = [0, 60, 45, 45, 45, 45, 45, 45]
angles = [0, 90, 30, 45, 45, 45, 45, 45]
angles = [45, 45, 30, 30, 45, 70, 45, 45]

angles = [(0, 1, 0, .5), (0.8, .4, .8, .2), (.5, .6, .7, .8)]

#angles=[0, 90, 30, 0, 90, 90,45,45,45,45,45,45,45,45,45]
#angles=[0, 90, 30, 30, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45]
#angles=[45, 45, 25, 10, 45, 45, 30, 45, 45, 45, 45, 45, 45, 45, 45]
#angles=[25, 60, 35, 35, 75, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45]
#angles=[0, 45,45,45,45,45,45,45,45,45,45,45,45,45,45]
#angles=[0,45, 45]
#coverage=[]