Created
January 8, 2013 10:56
-
-
Save carlobaldassi/4482894 to your computer and use it in GitHub Desktop.
Test mixintprog-based resolve(). The function is just Pkg.update() up to the call to Metadata.resolve(), with the resolve() code inlined.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("pkg") | |
myresolve() = Pkg.cd_pkgdir() do | |
have = (String=>ASCIIString)[] | |
reqs = Metadata.parse_requires("REQUIRE") | |
Git.each_submodule(false) do pkg, path, sha1 | |
if pkg != "METADATA" | |
have[pkg] = sha1 | |
end | |
end | |
sort!(reqs) | |
pkgs = Metadata.packages() | |
vers = Metadata.versions(pkgs) | |
deps = Metadata.dependencies(pkgs,vers) | |
n = length(vers) | |
z = zeros(Int,n) | |
u = ones(Int,n) | |
G = [ v == d[1] ? 1 : 0 for v=vers, d=deps ] | |
G *= [ contains(d[2],v) ? 1 : 0 for d=deps, v=vers ] | |
G += [ Metadata.older(a,b) ? 2 : 0 for a=vers, b=vers ] | |
I = find(G) | |
W = zeros(Int,length(I),n) | |
for (r,i) in enumerate(I) | |
W[r,rem(i-1,n)+1] = -1 | |
W[r,div(i-1,n)+1] = G[i] | |
end | |
mipopts = GLPK.IntoptParam() | |
mipopts["msg_lev"] = GLPK.MSG_ERR | |
mipopts["presolve"] = GLPK.ON | |
_, ws, flag, _ = LinProgGLPK.mixintprog(u,W,-ones(Int,length(I)),nothing,nothing,u,nothing,nothing,mipopts) | |
if flag != 0 | |
msg = sprint(print_linprog_flag, flag) | |
error("resolve() failed: $msg.") | |
end | |
w = iround(ws) | |
V = [ p == v.package ? 1 : 0 for p=pkgs, v=vers ] | |
R = [ contains(r,v) ? -1 : 0 for r=reqs, v=vers ] | |
D = [ d[1] == v ? 1 : contains(d[2],v) ? -1 : 0 for d=deps, v=vers ] | |
b = [ ones(Int,length(pkgs)) | |
-ones(Int,length(reqs)) | |
zeros(Int,length(deps)) ] | |
_, xs, flag, flag2 = LinProgGLPK.mixintprog(w,[V;R;D],b,nothing,nothing,z,u,nothing,mipopts) | |
if flag != 0 | |
msg = sprint(print_linprog_flag, flag) | |
error("resolve() failed: $msg.") | |
end | |
x = bool(xs) | |
h = (String=>ASCIIString)[] | |
for v in vers[x] | |
h[v.package] = readchomp("METADATA/$(v.package)/versions/$(v.version)/sha1") | |
end | |
return h | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment