##### Functions #### Functions #### Functions #### Functions #### Functions ####
#####################################################################
def Tcode(T,n):
code=[]
for index in range(n):
for index2 in range(n):
if blank[index][n-index2-1] !=0:
code.append([blank[index][n-index2-1],index])
return(code)
#####################################################################
################# Tcode() ############################################
def Tcode(T,n):
code=[]
for index in range(n):
for index2 in range(n):
if blank[index][n-index2-1] !=0:
code.append([blank[index][n-index2-1],index])
return(code)
#####################################################################
################### compare() ###################################################
# input: two integers
# output: 1 if they are comparable and 0 else
#################################################################################
def compare(i,j):
comparable=2
if i < j:
if h[i-1]<j:
comparable = 1
else:
comparable=0
if j<i:
if h[j-1]<i:
comparable=1
else:
comparable=0
if j ==0:
comparable =2
return(comparable)
###############################################################################
########################## column() ###########################################
# input: T is tableu, i is the column you want to identify
# output: A list of the elements in the ith column
###############################################################################
def column(T,i):
col=[]
for index in range(len(T)):
col.append(T[index][i-1])
return(col)
###############################################################################
################# insertion() #######################################################
# input: column, codeindex, matrix of tableau
# output: new tableau
#####################################################################################
def insertion(column,codeindex,codeitem,code1):
C = column
list1=[]
for index2 in range(len(C)-1):
#print code1[codeindex][0],C[index2]
#print compare(code1[codeindex][0],C[index2])
if compare(code1[codeindex][0],C[index2]) ==1:
#print "H2",code[codeindex][0],C[index2]
if code1[codeindex][0] < C[index2]:
#list1.append(C[index2])
C[index2]=code1[codeindex][0]
break
if compare(code1[codeindex][0],C[index2]) ==2:
C[index2]=codeitem[0]
#print "H1", code1[codeindex][0],C[index2+1]
break
if compare(code1[codeindex][0],C[index2]) ==0:
#print "H3", code1[codeindex][0], C[index2]
if compare(code1[codeindex][0],C[index2+1]) ==2:
#print "H31"
list1.append([C[index2],code1[codeindex][1]])
C[index2]=codeitem[0]
break
if compare(code1[codeindex][0],C[index2+1]) ==1:
list1.append([C[index2],code1[codeindex][1]])
#print "H32"
#print C[index2]
C[index2]=codeitem[0]
if compare(code1[codeindex][0],C[index2+1])==0:
#print "H33"
list1.append(code1[codeindex])
break
return(C,list1)
######################################################################################
######################## columninsert(C,codelist) #######################################################
# input: Column C, codelist = list of integers to be inserted with their corresponding row of tableau
# output: Column of Tableau and codelist for next insertion
#########################################################################################################
def columninsert(C,codelist):
list1=[]
for index in range(len(codelist)):
(C,D)= insertion(C,index,codelist[index],codelist)
if D!=[]:
for item in D:
list1.append(item)
return(C,list1)
#########################################################################################################
############# END OF FUNCTIONS ### END OF FUNCTIONS #### END OF FUNCTIONS #### END OF FUNCTIONS #### END OF FUNCTIONS ####
#################### START OF CODE ################# START OF CODE ################# START OF CODE #######################
n = 5
h=[2,3,4,5,5]
blank=[]
for index in range(n):
blank.append([])
for index2 in range(n):
blank[index].append(0)
blank[0][0]=3
blank[0][1]=2
blank[0][2]=1
blank[1][0]=4
blank[1][1]=5
T = blank
codelist =Tcode(T,n)
print "Hessenberg Function: ", h
columns=[]
for index in range(3):
D = [0,0,0,0,0]
(D,codelist)= columninsert(D,codelist)
print D
columns.append(D)
print codelist
print "The Tableau is "
print matrix(columns).transpose()
############## END OF CODE ############## END OF CODE ############## END OF CODE ############## END OF CODE ####################
print
print "Wow that is really short code that worked for once!"
|
|
Hessenberg Function: [2, 3, 4, 5, 5]
[3, 5, 0, 0, 0]
[[1, 0], [2, 0], [4, 1]]
[2, 4, 0, 0, 0]
[[1, 0]]
[1, 0, 0, 0, 0]
[]
The Tableau is
[3 2 1]
[5 4 0]
[0 0 0]
[0 0 0]
[0 0 0]
Wow that is really short code that worked for once!
Hessenberg Function: [2, 3, 4, 5, 5]
[3, 5, 0, 0, 0]
[[1, 0], [2, 0], [4, 1]]
[2, 4, 0, 0, 0]
[[1, 0]]
[1, 0, 0, 0, 0]
[]
The Tableau is
[3 2 1]
[5 4 0]
[0 0 0]
[0 0 0]
[0 0 0]
Wow that is really short code that worked for once!
|