Skip to content

Commit

Permalink
code indent size update -> 2
Browse files Browse the repository at this point in the history
  • Loading branch information
chkwon committed Nov 23, 2016
1 parent 5277a10 commit 2adec25
Show file tree
Hide file tree
Showing 16 changed files with 385 additions and 385 deletions.
4 changes: 2 additions & 2 deletions chap2/LP2.jl
Expand Up @@ -20,10 +20,10 @@ print(m)

println("Optimal Solutions:")
for i=1:3
println("x[$i] = ", getvalue(x[i]))
println("x[$i] = ", getvalue(x[i]))
end

println("Dual Variables:")
for j=1:2
println("dual[$j] = ", getdual(constraint[j]))
println("dual[$j] = ", getdual(constraint[j]))
end
6 changes: 3 additions & 3 deletions chap2/LP3.jl
Expand Up @@ -14,7 +14,7 @@ index_constraints = 1:2
@objective(m, Max, sum{ c[i]*x[i], i in index_x} )

@constraint(m, constraint[j in index_constraints],
sum{ A[j,i]*x[i], i in index_x } <= b[j] )
sum{ A[j,i]*x[i], i in index_x } <= b[j] )

@constraint(m, bound, x[1] <= 10)

Expand All @@ -24,10 +24,10 @@ print(m)

println("Optimal Solutions:")
for i in index_x
println("x[$i] = ", getvalue(x[i]))
println("x[$i] = ", getvalue(x[i]))
end

println("Dual Variables:")
for j in index_constraints
println("dual[$j] = ", getdual(constraint[j]))
println("dual[$j] = ", getdual(constraint[j]))
end
44 changes: 22 additions & 22 deletions chap3/basics.jl
Expand Up @@ -77,41 +77,41 @@ println("b is $b.")
println("The second element of b is $(b[2]).")
@printf("The %s of a = %f", "value", a)

c = [ 123.12345 ;
10.983 ;
1.0932132 ]
c = [ 123.12345 ;
10.983 ;
1.0932132 ]
for i in 1:length(c)
println("c[$i] = $(c[i])")
println("c[$i] = $(c[i])")
end
for i in 1:length(c)
@printf("c[%d] = %7.3f\n", i, c[i])
@printf("c[%d] = %7.3f\n", i, c[i])
end

str = @sprintf("The %s of a = %f", "value", a)
println(str)

for i in 1:5
println("This is number $i.")
println("This is number $i.")
end

for i in 1:5
if i >= 3
break
end
println("This is number $i.")
if i >= 3
break
end
println("This is number $i.")
end

s = 0
for i in 1:length(a)
s += a[i]
s += a[i]
end

my_keys = ["Zinedine Zidane", "Magic Johnson", "Yuna Kim"]
my_values = ["football", "basketball", "figure skating"]

d = Dict()
for i in 1:length(my_keys)
d[my_keys[i]] = my_values[i]
d[my_keys[i]] = my_values[i]
end
@show d
for (key, value) in d
Expand All @@ -125,11 +125,11 @@ links = [ (1,2), (3,4), (4,2) ]
link_costs = [ 5, 13, 8 ]
link_dict = Dict()
for i in 1:length(links)
link_dict[ links[i] ] = link_costs[i]
link_dict[ links[i] ] = link_costs[i]
end
@show link_dict
for (link, cost) in link_dict
println("Link $link has cost of $cost.")
println("Link $link has cost of $cost.")
end


Expand All @@ -155,27 +155,27 @@ x, y = my_func(3,2)

# Scope of variables
function f1(x)
return x+a
return x+a
end
a = 0
for i in 1:10
a = i
println(f1(1))
a = i
println(f1(1))
end


function f2(x)
a = 0
return x+a
a = 0
return x+a
end
a = 5
println(f2(1))
println(a)


function f3(x)
_a = 0
return x + _a
_a = 0
return x + _a
end

a = 5
Expand All @@ -184,7 +184,7 @@ println(a)


function f4(x, a)
return x + a
return x + a
end

a = 5
Expand Down
56 changes: 28 additions & 28 deletions chap5/search_bfs.jl
@@ -1,38 +1,38 @@
using Combinatorics

function isnonnegative(x::Array{Float64, 1})
return length( x[ x .< 0] ) == 0
return length( x[ x .< 0] ) == 0
end

function searchBFS(c, A, b)
m, n = size(A)
@assert rank(A) == m

opt_x = zeros(n)
obj = Inf

for b_idx in combinations(1:n, m)
B = A[:, b_idx]
c_B = c[b_idx]
x_B = inv(B) * b

if isnonnegative(x_B)
z = dot(c_B, x_B)
if z < obj
obj = z
opt_x = zeros(n)
opt_x[b_idx] = x_B
end
end

println("Basis:", b_idx)
println("\t x_B = ", x_B)
println("\t nonnegative? ", isnonnegative(x_B))
if isnonnegative(x_B)
println("\t obj = ", dot(c_B, x_B))
end
m, n = size(A)
@assert rank(A) == m

opt_x = zeros(n)
obj = Inf

for b_idx in combinations(1:n, m)
B = A[:, b_idx]
c_B = c[b_idx]
x_B = inv(B) * b

if isnonnegative(x_B)
z = dot(c_B, x_B)
if z < obj
obj = z
opt_x = zeros(n)
opt_x[b_idx] = x_B
end
end

println("Basis:", b_idx)
println("\t x_B = ", x_B)
println("\t nonnegative? ", isnonnegative(x_B))
if isnonnegative(x_B)
println("\t obj = ", dot(c_B, x_B))
end

return opt_x, obj
end

return opt_x, obj
end

0 comments on commit 2adec25

Please sign in to comment.