Skip to content

Commit

Permalink
Bug fix and minor improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
YouenL committed Oct 13, 2016
1 parent 4757b11 commit d5e9cae
Show file tree
Hide file tree
Showing 17 changed files with 367 additions and 382 deletions.
12 changes: 5 additions & 7 deletions Turbine/algorithms/normalized.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
from fractions import Fraction
from math import ceil

from numpy.random.mtrand import randint

from Turbine.calc.lcm import lcm


def normalized_dataflow(dataflow):
def normalized_dataflow(dataflow, coef_vector=None):
"""Normalize a dataflow and return the coefficient vector to un-normalized it.
Return
------
:return the un-normalize graph.
"""
if not dataflow.is_consistent:
raise Exception("Dataflow must be consistent to be normalized")
raise RuntimeError("Dataflow must be consistent to be normalized")
if dataflow.is_normalized:
return dataflow
return

coef_vector = get_normalized_vector(dataflow)
if coef_vector is None:
coef_vector = get_normalized_vector(dataflow)

for arc in dataflow.get_arc_list():
multiply_arc(dataflow, arc, coef_vector[arc])

for arc in dataflow.get_arc_list():
coef_vector[arc] = Fraction(numerator=1, denominator=coef_vector[arc])

return coef_vector


Expand Down
23 changes: 10 additions & 13 deletions Turbine/algorithms/solve_SC1.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def __init_prob(self): # Modify parameters
# GLPK parameters:
self.glpk_param = glp_smcp()
glp_init_smcp(self.glpk_param) # Do it before modify parameters

self.glpk_param.presolve = GLP_ON
self.glpk_param.msg_lev = GLP_MSG_ALL
if not self.verbose:
Expand Down Expand Up @@ -161,7 +160,6 @@ def __create_row(self): # Add Row (constraint) on prob

str_v1 = str(source) + "/" + str(source_phase)
str_v2 = str(target) + "/" + str(target_phase)

self.__add_row(row, str_v1, str_v2, arc, w)
row += 1
# END FILL ROW
Expand Down Expand Up @@ -222,7 +220,7 @@ def __solve_prob(self): # Launch the solver and set preload of the graph
# Add a variable lamda
def __add_col_v(self, col, name):
glp_set_col_name(self.prob, col, name)
glp_set_col_bnds(self.prob, col, GLP_FR, 0, 0)
glp_set_col_bnds(self.prob, col, GLP_LO, 0, 0)
glp_set_obj_coef(self.prob, col, 0.0)
self.colV[name] = col

Expand All @@ -243,23 +241,22 @@ def __add_col_fm0(self, col, name, arc):

# Add a constraint: lambda1 - lambda2 + M0 > W1
def __add_row(self, row, str_v1, str_v2, arc, w):
if self.dataflow.get_source(arc) != self.dataflow.get_target(arc):
self.var_row[self.k] = row
self.var_col[self.k] = self.colV[str_v1]
self.var_coef[self.k] = 1.0
self.k += 1
self.var_row[self.k] = row
self.var_col[self.k] = self.colV[str_v1]
self.var_coef[self.k] = 1.0
self.k += 1

self.var_row[self.k] = row
self.var_col[self.k] = self.colV[str_v2]
self.var_coef[self.k] = -1.0
self.k += 1
self.var_row[self.k] = row
self.var_col[self.k] = self.colV[str_v2]
self.var_coef[self.k] = -1.0
self.k += 1

self.var_row[self.k] = row
self.var_col[self.k] = self.col_m0[arc]
self.var_coef[self.k] = 1.0
self.k += 1

glp_set_row_bnds(self.prob, row, GLP_LO, w + 0.0000001, 0.0) # W1+1 cause there is no strict bound with GLPK
glp_set_row_bnds(self.prob, row, GLP_LO, w + 0.001, 0.0) # W1+1 cause there is no strict bound with GLPK
glp_set_row_name(self.prob, row, "r_" + str(row))

# Add a constraint: FM0*step = M0
Expand Down
12 changes: 5 additions & 7 deletions Turbine/algorithms/solve_SC1_Gurobi_MIP.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def compute_initial_marking(self):

def __init_prob(self): # Modify parameters
logging.info("Generating initial marking problem")
self.prob = Model("SC1")
self.prob = Model("SC1_MIP")

# Gurobi parameters:
if not self.verbose:
Expand All @@ -46,11 +46,10 @@ def __init_prob(self): # Modify parameters
os.remove("gurobi.log")
except OSError:
pass
self.prob.params.Threads = 4
self.prob.params.Threads = 2
self.prob.params.intfeastol = 0.000001

def __create_col(self): # Add Col on prob
# Counting column

# Create column bds (M0)
for arc in self.dataflow.get_arc_list():
self.__add_col_m0(arc)
Expand Down Expand Up @@ -140,7 +139,7 @@ def __solve_prob(self): # Launch the solver and set preload of the graph
if not self.dataflow.is_arc_reentrant(arc):
self.dataflow.set_initial_marking(arc, int(self.col_m0[arc].x))

logging.info("SC1 Mem tot (no reentrant): " + str(self.Z))
logging.info("SC1 MIP Mem tot (no reentrant): " + str(self.Z))

# Add a variable lamda
def __add_col_v(self, name):
Expand All @@ -165,14 +164,13 @@ def __add_row(self, str_v1, str_v2, arc, w):
expr -= self.col_v[str_v2]
expr += self.col_m0[arc]

self.prob.addConstr(expr, GRB.GREATER_EQUAL, w + 1)
self.prob.addConstr(expr, GRB.GREATER_EQUAL, w + 0.00001)

# Add a constraint: FM0*step = M0
def __add_frow(self, arc, step):
expr = LinExpr()
expr += self.col_fm0[arc]*float(step)
expr -= self.col_m0[arc]

self.prob.addConstr(expr, GRB.EQUAL, 0)

def __get_range_phases(self, task):
Expand Down
Loading

0 comments on commit d5e9cae

Please sign in to comment.