-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSparseReader.py
More file actions
38 lines (32 loc) · 1.07 KB
/
Copy pathSparseReader.py
File metadata and controls
38 lines (32 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 5 11:27:32 2021
@author: aoust
"""
import numpy as np
from QuadraticPolynomial import QuadraticPolynomial
class SparseReader():
def __init__(self,fileobj):
file = open(fileobj)
#Reading n and m
line = (file.readline())
array = line.split(" ")
self.n,self.m = int(array[0]), int(array[1])
tup = []
coefs = []
for k in range(self.m):
line = (file.readline())
array = line.split(" ")
i,j, val = int(array[0]), int(array[1]), float(array[2])
tup.append((i-1,j-1))
if i==j:
coefs.append(val)
else:
assert(i<j)
coefs.append(2*val)
self.objective_polynomial = QuadraticPolynomial(self.n,tup,np.array(coefs))
# m = 0
# for idx in range(1000):
# x = np.random.randint(2, size=self.n)
# m = min(m,(self.objective_polynomial.evaluation(x)))
# print("minimum = {0}".format(m))