Language: C++

import csv
import cvxpy as cvx
import numpy

m = 100
weight_sum = 100
weight_modi = [[2 for i in range(m)] for j in range(m)]

numpy.random.seed(1)

s = numpy.random.rand(m)
s_mean = s.mean()
s_dev = s - s_mean * numpy.ones(m)
s_tdev = s_dev.reshape(m,1)

unit = numpy.eye(m)
One = numpy.ones(m)

L = cvx.Variable((m,m))

W_neg = L-cvx.diag(cvx.diag(L))
W = -1*W_neg

degree = W * One


objective = cvx.Minimize(cvx.matrix_frac(s_tdev,unit + L))

constraints = [L == L.T, cvx.trace(L) == 2*weight_sum ,W >= 0,cvx.diag(L) >= 0, degree == cvx.diag(L)]

prob = cvx.Problem(objective, constraints)

print("----------------------------- START")
print("Optimal value d+p : ")
print(prob.solve())
print("-----------------------------")
print(prob.solve(solver=cvx.SCS))
print("-----------------------------")
print("Optimal var L : ")
print(L.value)
print("-----------------------------")
print("value of s : ")
print(s)
print("-----------------------------")
#print(s_mean)
#print(s_t)
#print(s @ s_t)
#print(u)
print("value of s_eq : " )
print(numpy.dot(numpy.linalg.inv(unit+L.value),s))
print("-----------------------------")
print("value of s_dev : ")
print(s_dev)
#print(u @ s_t)
#print(s @ u)
print("-----------------------------")
#print(s @ u @ s_t)
#print(s_dev_diag)
# LP = L-A
# W(weight matrix) = LP + A(adjacent matrix) - I(unit matrix)
print("weight : ")
print(W.value)
print("-----------------------------")
print("degree : ")
print(degree.value)
print("-----------------------------")
print("W[1][2] :")
print(W.value[0][1])
print("----------------------------- END")
l = 0
k = 0
for i in range(0,m):
	for j in range(0,m):
		if W.value[i][j] < 0.000001:
			weight_modi[i][j] = 0
		else:
			weight_modi[i][j] = 1 
			l += 1
print(weight_modi[0][1])
numpy.savetxt("weight_cut.csv",weight_modi[1],delimiter="\n")
cytoscape = [[2 for i in range(2)] for j in range(l)]
for i in range(0,m):
	for j in range(0,m):
		if weight_modi[i][j] == 1:
			cytoscape[k][0] = i
			cytoscape[k][1] = j
			k += 1
with open('./cytoscape.csv', 'w') as f:
    writer = csv.writer(f)
    writer.writerows(cytoscape)



Compiler output:
a.cc:45:2: error: invalid preprocessing directive #print
   45 | #print(s_mean)
      |  ^~~~~
a.cc:46:2: error: invalid preprocessing directive #print
   46 | #print(s_t)
      |  ^~~~~
a.cc:47:2: error: invalid preprocessing directive #print
   47 | #print(s @ s_t)
      |  ^~~~~
a.cc:48:2: error: invalid preprocessing directive #print
   48 | #print(u)
      |  ^~~~~
a.cc:54:2: error: invalid preprocessing directive #print
   54 | #print(u @ s_t)
      |  ^~~~~
a.cc:55:2: error: invalid preprocessing directive #print
   55 | #print(s @ u)
      |  ^~~~~
a.cc:57:2: error: invalid preprocessing directive #print
   57 | #print(s @ u @ s_t)
      |  ^~~~~
a.cc:58:2: error: invalid preprocessing directive #print
   58 | #print(s_dev_diag)
      |  ^~~~~
a.cc:59:3: error: invalid preprocessing directive #LP
   59 | # LP = L-A
      |   ^~
a.cc:60:3: error: invalid preprocessing directive #W
   60 | # W(weight matrix) = LP + A(adjacent matrix) - I(unit matrix)
      |   ^
a.cc:88:11: warning: multi-character literal with 15 characters exceeds 'int' size of 4 bytes
   88 | with open('./cytoscape.csv', 'w') as f:
      |           ^~~~~~~~~~~~~~~~~
a.cc:1:1: error: 'import' does not name a type
    1 | import csv
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'