text_plain_output_1.png
target_url = 'https://filebox.ece.vt.edu/~mhsiao/ISCAS89/s27.bench'
import urllib.request
outputs = []
inputs = []
for line in urllib.request.urlopen(target_url):
    l = line.decode('utf-8')
    if '=' in l:
        parse = l.split(' = ')
        outputs.append(parse[0])
        inputs.append(parse[1].split('(')[1].split(')')[0].split(', '))

n = len(outputs)
edges = []
for i in range(n):
    out = outputs[i]
    for j in range(n):
        if out in inputs[j]:
            edges.append([i + 1, j + 1])

def PC(chromosome, edges):
    partition0 = []
    partition1 = []
    for i in range(len(chromosome)):
        if chromosome[i] == '0':
            partition0.append(i + 1)
        else:
            partition1.append(i + 1)
    pc = 0
    for i in edges:
        x, y = (i[0], i[1])
        if x in partition0 and y in partition1 or (x in partition1 and y in partition0):
            pc += 1
    return pc
print(PC('000111', [[1, 2], [1, 3], [2, 4], [3, 6], [4, 5], [5, 6]]))