From 9efbda92d452f20f8333667eb6ff0e25568c4a52 Mon Sep 17 00:00:00 2001 From: anteprandium Date: Tue, 20 Oct 2015 14:32:57 +0200 Subject: [PATCH 01/15] cached best; added first walk back. --- ipproblem.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) mode change 100644 => 100755 ipproblem.py diff --git a/ipproblem.py b/ipproblem.py old mode 100644 new mode 100755 index cbb1b02..150ed8d --- a/ipproblem.py +++ b/ipproblem.py @@ -1,4 +1,5 @@ -# coding=utf-8 +#!/usr/bin/env /Users/soto/Scripts/sage -python +# encoding: utf-8 """ Algorithms for computing test sets of Integer Programming problems. @@ -49,6 +50,7 @@ def __init__(self, c, A, b, u=None): self.b = vector(ZZ,b) self.c = vector(ZZ,c) self.minimal=None + self.best=None self.non_reducible=None self.rows=self.A.nrows() self.cols=self.A.ncols() @@ -334,6 +336,8 @@ def test_set_non_reducibles(self): def walk_to_best(self,s, path=False): """Given a feasible solution $s$, walk from $s$ to the optimum. Return the optimum, or, if `path` is `True`, the full path from `s` to the optimum. """ + if self.best: + return self.best s_0=vector(ZZ,s) if not self.is_feasible(s_0): return False @@ -362,6 +366,7 @@ def walk_to_best(self,s, path=False): cont=any(F) else: cont=False + self.best=s_0 if path: return path_l else: @@ -389,3 +394,60 @@ def __repr__(self): b=%s, u=%s.""" return s % (self.c, self.A, self.b, self.u) + + + def walkback(self, region=lambda x: True): + """ + Start a walk back from the optimus of the regular problem + to an optimus which is also within the region determined by + the function `region` (Might be non-linear). + + >>> P=IPProblem(c=[3, 4, 3, 6, 3],A=[[3, 2, 1, 5, 7]], b=[4], u=[1,1,1,1,1] ) + >>> P.minimal_test_set() + [(1, 0, 0, 0, 0), (0, 1, 0, 0, 0), (0, 0, 1, 0, 0), (-1, 1, 0, 0, 0), (1, 0, -1, 0, 0), (0, 1, -1, 0, 0)] + >>> P.walk_to_best(P.get_feasible()) + (0, 1, 1, 0, 0) + >>> P.walkback(region=lambda x: x[0]**2+x[1]**2<2) + """ + # Sort a minimal test set by increasing cost. + T=sorted(self.minimal_test_set(), key=self.cost) + first_point=self.walk_to_best(self.get_feasible(), False) + visited=[] + current_best=False + current_cost=False + S=[first_point] # the first point is always feasible. + while S: + v=S.pop(0) # Get first in queue + c=self.cost(v) + + # Cross out from future examinations + if not v in visited: + visited.append(v) + # see if it's better than what we have so far + # if self.is_feasible(v) and region(v): + if region(v): # we can skip feasibility, since we only include feasibles. + if not current_cost or c current_cost)): + verbose("appending %s"%w, level=2) + S.append(w) + + verbose("|S|=%d"%len(S), level=1) + if current_cost: + return current_best, current_cost + else: + return None + + +if __name__ == '__main__': + import doctest + doctest.testmod() + + + \ No newline at end of file From eadb76cab91c6f1aab18763a2b17492cedf5d1c3 Mon Sep 17 00:00:00 2001 From: anteprandium Date: Tue, 20 Oct 2015 16:09:23 +0200 Subject: [PATCH 02/15] Bug fix * Sometimes it would cycle, due to a bug in cost comparison. * Other times, it would revisit already known points. * Also, it would duplicate points in the waiting list. --- ipproblem.py | 23 +- optimus_check.ipynb | 549 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 535 insertions(+), 37 deletions(-) diff --git a/ipproblem.py b/ipproblem.py index 150ed8d..b3fb867 100755 --- a/ipproblem.py +++ b/ipproblem.py @@ -1,4 +1,4 @@ -#!/usr/bin/env /Users/soto/Scripts/sage -python +#!/usr/bin/env sage -python # encoding: utf-8 """ @@ -407,7 +407,8 @@ def walkback(self, region=lambda x: True): [(1, 0, 0, 0, 0), (0, 1, 0, 0, 0), (0, 0, 1, 0, 0), (-1, 1, 0, 0, 0), (1, 0, -1, 0, 0), (0, 1, -1, 0, 0)] >>> P.walk_to_best(P.get_feasible()) (0, 1, 1, 0, 0) - >>> P.walkback(region=lambda x: x[0]**2+x[1]**2<2) + >>> P.walkback(region=lambda x: x[0]**2+x[1]**2+x[2]**2<2) + ((0, 1, 0, 0, 0), 4) """ # Sort a minimal test set by increasing cost. T=sorted(self.minimal_test_set(), key=self.cost) @@ -418,36 +419,40 @@ def walkback(self, region=lambda x: True): S=[first_point] # the first point is always feasible. while S: v=S.pop(0) # Get first in queue + verbose("|S|=%d"%len(S), level=2) c=self.cost(v) # Cross out from future examinations - if not v in visited: + if v in visited: + break + else: visited.append(v) # see if it's better than what we have so far # if self.is_feasible(v) and region(v): if region(v): # we can skip feasibility, since we only include feasibles. - if not current_cost or ccurrent_cost: current_best,current_cost=v,c + verbose("current best=%s, current_cost=%s"%(current_best, current_cost), level=1) # Now, look at sons. for d in T: w = v-d # You'll be worsening things here. new_c = self.cost(w) if (self.is_feasible(w) and + not w in S and not w in visited and - (not current_cost or new_c > current_cost)): + (current_cost is None or new_c > current_cost)): verbose("appending %s"%w, level=2) S.append(w) - verbose("|S|=%d"%len(S), level=1) if current_cost: return current_best, current_cost else: return None -if __name__ == '__main__': - import doctest - doctest.testmod() +# if __name__ == '__main__': +# import doctest +# doctest.testmod() \ No newline at end of file diff --git a/optimus_check.ipynb b/optimus_check.ipynb index b76ae78..a2b54ae 100644 --- a/optimus_check.ipynb +++ b/optimus_check.ipynb @@ -11,18 +11,18 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ - "#%load_ext sage" + "%load_ext sage" ] }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 13, "metadata": { "collapsed": false }, @@ -272,7 +272,58 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 15, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "set_verbose(0)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The sage extension is already loaded. To reload it, use:\n", + " %reload_ext sage\n" + ] + } + ], + "source": [ + "%load_ext sage" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%run ipproblem.py" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 39, "metadata": { "collapsed": false }, @@ -284,10 +335,10 @@ "Integer programming problem\n", " max\\{c.x : A x <= b, 0<=x<=u\\}\n", "with\n", - "c=(78, 64, 58, 75, 63, 51, 79, 66, 85, 36),\n", + "c=(20, 63, 90, 47, 45, 28, 55, 68, 44, 64),\n", "A=\n", - "[24 20 21 13 10 28 26 12 14 29],\n", - "b=(81),\n", + "[19 19 29 18 19 20 14 25 24 14],\n", + "b=(65),\n", "u=(1, 1, 1, 1, 1, 1, 1, 1, 1, 1).\n" ] } @@ -304,29 +355,26 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 40, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " " - ] - } - ], + "outputs": [], "source": [ - "%%prun \n", + "#%%prun \n", "#%%time\n", "\n", + "P=IPProblem(c=(80, 39, 29, 61, 66, 74, 52, 29, 40, 62), \n", + " A=[[14, 20, 27, 10, 19, 14, 23, 18, 23, 20]], \n", + " b=[66],\n", + " u=(1, 1, 1, 1, 1, 1, 1, 1, 1, 1))\n", + "\n", "L=P.minimal_test_set()\n" ] }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 41, "metadata": { "collapsed": false }, @@ -334,26 +382,471 @@ { "data": { "text/plain": [ - "97" + "((1, 0, 0, 1, 1, 1, 0, 0, 0, 0), 281)" ] }, - "execution_count": 42, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "len(L)" + "x=P.walk_to_best(P.get_feasible())\n", + "x, P.cost(x)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": { "collapsed": false }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "verbose 2 (399: ipproblem.py, walkback) |S|=0\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 1, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 1, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 1, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 1, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 1, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 1, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 1, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 1, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 1, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 1, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 1, 1, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 1, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 1, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 1, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 1, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 1, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 1, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 1, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=20\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 1, 0, 1, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 1, 0, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 1, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 0, 1, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 0, 1, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 1, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=27\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=28\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 1, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 1, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 1, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=32\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 1, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=32\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=33\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 0, 1, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 0, 1, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 1, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=37\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 1, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 1, 0, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 1, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 1, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=42\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 1, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=42\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 1, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 1, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=44\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=45\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 1, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 1, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=46\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 1, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=48\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=49\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 1, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=49\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 1, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=49\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=49\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=48\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 1, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 1, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=52\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=53\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 1, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=54\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=53\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 1, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 1, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=54\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=55\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 1, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=55\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 1, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=55\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=54\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 1, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 1, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 0, 1, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 0, 1, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 0, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 1, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=61\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 1, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 0, 1, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 0, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=64\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=63\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 1, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 0, 1, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 1, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 1, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 1, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=68\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=67\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 1, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 1, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=68\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 1, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=68\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 1, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 1, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 1, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 0, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 1, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=75\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 1, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 0, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=78\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=77\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=76\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 1, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 1, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 1, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=79\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=78\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 1, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 1, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=79\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 1, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=79\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 1, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 0, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 1, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=84\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 0, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=86\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=85\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 1, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=86\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=86\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=85\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 1, 0, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 1, 0, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 1, 1, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=87\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 0, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 1, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=90\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 1, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 1, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 1, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=93\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=92\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 1, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=93\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=92\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 1, 0, 1, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 1, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=93\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=92\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=93\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 0, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=94\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=93\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=93\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=92\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=91\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=90\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 1, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", + "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=87\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=86\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=85\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 1, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 1, 1, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 1, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 0, 0, 1, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 1, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 1, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 0, 1, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=90\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=87\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 0, 1, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=87\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 0, 1, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=87\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=86\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=86\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=85\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 0, 0, 1)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=85\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=84\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=83\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=82\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=81\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=80\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=79\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=78\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=77\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=76\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=75\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=74\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 1, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 1, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=76\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=75\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=74\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 1, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=75\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=75\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=74\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=73\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=73\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=72\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=72\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=71\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=70\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=69\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=68\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=67\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=66\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=65\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=64\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=63\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 1, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 1, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=64\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=63\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=62\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=62\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=61\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=61\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=60\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 0, 1, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=60\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=59\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=58\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=57\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=56\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 1, 0, 0, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=57\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=56\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=55\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 1, 0, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=55\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=54\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=54\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=53\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=52\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=51\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=51\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=50\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 1, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=50\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=49\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=48\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=47\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=46\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=45\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=44\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=43\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=42\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=41\n", + "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 0, 0, 0, 0, 0)\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=41\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=40\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=39\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=38\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=37\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=36\n", + "verbose 1 (399: ipproblem.py, walkback) current best=(1, 0, 0, 0, 0, 0, 0, 0, 0, 0), current_cost=80\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=35\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=34\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=33\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=32\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=31\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=30\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=29\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=28\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=27\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=26\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=25\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=24\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=23\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=22\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=21\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=20\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=19\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=18\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=17\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=16\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=15\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=14\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=13\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=12\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=11\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=10\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=9\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=8\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=7\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=6\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=5\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=4\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=3\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=2\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=1\n", + "verbose 2 (399: ipproblem.py, walkback) |S|=0\n", + "((1, 0, 0, 0, 0, 0, 0, 0, 0, 0), 80)\n" + ] + } + ], + "source": [ + "set_verbose(2)\n", + "f=P.walkback(region=lambda v: add([v[i]**2 for i in range(len(v))])<2)\n", + "print f\n", + "set_verbose(0)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": true + }, "outputs": [], - "source": [] + "source": [ + "L=range(10)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6, 7, 8, 9]\n", + "[2, 3, 4, 5, 6, 7, 8, 9]\n", + "[3, 4, 5, 6, 7, 8, 9]\n", + "[4, 5, 6, 7, 8, 9]\n", + "[5, 6, 7, 8, 9]\n", + "[6, 7, 8, 9]\n", + "[7, 8, 9]\n", + "[8, 9]\n", + "[9]\n", + "[]\n" + ] + } + ], + "source": [ + "while L:\n", + " L.pop(0)\n", + " print L" + ] }, { "cell_type": "code", @@ -367,9 +860,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Sage 6.6", - "language": "", - "name": "sage_6_6" + "display_name": "Python 2", + "language": "python", + "name": "python2" }, "language_info": { "codemirror_mode": { @@ -381,7 +874,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.8" + "version": "2.7.9" } }, "nbformat": 4, From 5a4beb8b7b67cb632f9f5b97f64efab51f7711e2 Mon Sep 17 00:00:00 2001 From: anteprandium Date: Wed, 21 Oct 2015 16:05:19 +0200 Subject: [PATCH 03/15] Added sketch of proof --- ipproblem.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ipproblem.py b/ipproblem.py index b3fb867..8459bbe 100755 --- a/ipproblem.py +++ b/ipproblem.py @@ -409,6 +409,17 @@ def walkback(self, region=lambda x: True): (0, 1, 1, 0, 0) >>> P.walkback(region=lambda x: x[0]**2+x[1]**2+x[2]**2<2) ((0, 1, 0, 0, 0), 4) + + + !!! Nota: + Para demostrar que este algoritmo siempre calcula el óptimo con la restricción + adicional de la región, hay que argumentarlo. Creo que + una línea argumental positiva es la siguiente: Si el “esqueleto” que resulta + de considerar el test set da un grafo dirigido con fin en el óptimo, el grafo + con direcciones inversas empezando en el óptimo, con el algoritmo de + travesía de grafos en profundidad y con las aristas ordenadas en orden creciente, + recorre cada punto desde el coste mayor hacia abajo, y se queda con el máximo + cada vez que entra en la región determinada por `region`. """ # Sort a minimal test set by increasing cost. T=sorted(self.minimal_test_set(), key=self.cost) From 53fb1e2237fe9189c2c8a43f8d9f1be784119ef5 Mon Sep 17 00:00:00 2001 From: anteprandium Date: Wed, 23 Mar 2016 18:05:10 +0100 Subject: [PATCH 04/15] fixed bug in ipproblem and started wack back --- ipproblem.py | 2 +- optimus_check.ipynb | 464 ++------------------------------------------ wbtl.ipynb | 126 ++++++++++++ wbtl.py | 118 +++++++++++ 4 files changed, 257 insertions(+), 453 deletions(-) create mode 100644 wbtl.ipynb create mode 100755 wbtl.py diff --git a/ipproblem.py b/ipproblem.py index 8459bbe..92c6fde 100755 --- a/ipproblem.py +++ b/ipproblem.py @@ -343,7 +343,7 @@ def walk_to_best(self,s, path=False): return False T=self.minimal or self.non_reducible if not T: - self.minimal() + self.minimal_test_set() T=self.minimal F=[self.is_feasible(s_0+t) for t in T] path_l=[s_0] diff --git a/optimus_check.ipynb b/optimus_check.ipynb index a2b54ae..9bfd142 100644 --- a/optimus_check.ipynb +++ b/optimus_check.ipynb @@ -283,27 +283,18 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 1, "metadata": { "collapsed": false }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The sage extension is already loaded. To reload it, use:\n", - " %reload_ext sage\n" - ] - } - ], + "outputs": [], "source": [ "%load_ext sage" ] }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 2, "metadata": { "collapsed": false }, @@ -323,7 +314,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 3, "metadata": { "collapsed": false }, @@ -335,10 +326,10 @@ "Integer programming problem\n", " max\\{c.x : A x <= b, 0<=x<=u\\}\n", "with\n", - "c=(20, 63, 90, 47, 45, 28, 55, 68, 44, 64),\n", + "c=(66, 84, 70, 41, 47, 96, 59, 26, 66, 29),\n", "A=\n", - "[19 19 29 18 19 20 14 25 24 14],\n", - "b=(65),\n", + "[28 18 16 19 18 10 16 24 10 14],\n", + "b=(73),\n", "u=(1, 1, 1, 1, 1, 1, 1, 1, 1, 1).\n" ] } @@ -355,7 +346,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 4, "metadata": { "collapsed": false }, @@ -374,7 +365,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 5, "metadata": { "collapsed": false }, @@ -385,7 +376,7 @@ "((1, 0, 0, 1, 1, 1, 0, 0, 0, 0), 281)" ] }, - "execution_count": 41, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -397,7 +388,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 6, "metadata": { "collapsed": false }, @@ -406,448 +397,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "verbose 2 (399: ipproblem.py, walkback) |S|=0\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 1, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 1, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 1, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 1, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 1, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 1, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 1, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 1, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 1, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 1, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 1, 1, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 1, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 1, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 1, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 1, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 1, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 1, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 1, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=20\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 1, 0, 1, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 1, 0, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 1, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 0, 1, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 0, 1, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 1, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=27\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=28\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 1, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 1, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 1, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=32\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 1, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=32\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=33\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 0, 1, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 0, 1, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 1, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=37\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 1, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 1, 0, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 1, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 1, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=42\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 1, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=42\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 1, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 1, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=44\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=45\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 1, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 1, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=46\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 1, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=48\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=49\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 1, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=49\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 1, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=49\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=49\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=48\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 1, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 1, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 1, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=52\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 1, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=53\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 1, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 1, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=54\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=53\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 1, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 1, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=54\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=55\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 1, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=55\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 1, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=55\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=54\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 1, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 1, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 0, 1, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 0, 1, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 0, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 1, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=61\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 1, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 0, 1, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 0, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=64\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=63\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 1, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 0, 1, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 1, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 1, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 1, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=68\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=67\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 1, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 1, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=68\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 1, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=68\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 1, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 1, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 1, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 0, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 1, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=75\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 1, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 0, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=78\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=77\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=76\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 1, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 1, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 1, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=79\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=78\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 1, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 1, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=79\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 1, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=79\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 1, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 0, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 1, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=84\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 0, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=86\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=85\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 1, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=86\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=86\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=85\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 1, 0, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 1, 0, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 1, 0, 0, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 1, 1, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 1, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=87\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 0, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 1, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=90\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 1, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 1, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 1, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=93\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=92\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 1, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=93\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=92\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 1, 0, 1, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 1, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=93\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=92\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 1, 0, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=93\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 0, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 1, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=94\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=93\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=93\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=92\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=91\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=90\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 1, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", - "verbose 2 (399: ipproblem.py, walkback) appending (1, 0, 0, 0, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 1, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 1, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 1, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=87\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=86\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=85\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 1, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 1, 1, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 1, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 0, 0, 1, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 1, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 1, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 0, 1, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=90\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=89\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=87\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 0, 1, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=88\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=87\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 0, 1, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=87\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=86\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=86\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=85\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 0, 0, 1)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=85\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=84\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=83\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=82\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=81\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=80\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=79\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=78\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=77\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=76\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=75\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=74\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 1, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 1, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=76\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=75\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=74\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 1, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=75\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=75\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=74\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=73\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=73\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=72\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 1, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=72\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=71\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=70\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=69\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=68\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=67\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=66\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=65\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=64\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=63\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 1, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 1, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=64\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=63\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=62\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=62\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=61\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=61\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=60\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 0, 1, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=60\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=59\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=58\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=57\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=56\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 1, 0, 0, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=57\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=56\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=55\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 1, 0, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=55\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=54\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 1, 0, 0, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=54\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=53\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=52\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=51\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=51\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=50\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 0, 0, 0, 0, 0, 1, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=50\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=49\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=48\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=47\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=46\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=45\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=44\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=43\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=42\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=41\n", - "verbose 2 (399: ipproblem.py, walkback) appending (0, 0, 1, 0, 0, 0, 0, 0, 0, 0)\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=41\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=40\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=39\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=38\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=37\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=36\n", - "verbose 1 (399: ipproblem.py, walkback) current best=(1, 0, 0, 0, 0, 0, 0, 0, 0, 0), current_cost=80\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=35\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=34\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=33\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=32\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=31\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=30\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=29\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=28\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=27\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=26\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=25\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=24\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=23\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=22\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=21\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=20\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=19\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=18\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=17\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=16\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=15\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=14\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=13\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=12\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=11\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=10\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=9\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=8\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=7\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=6\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=5\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=4\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=3\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=2\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=1\n", - "verbose 2 (399: ipproblem.py, walkback) |S|=0\n", "((1, 0, 0, 0, 0, 0, 0, 0, 0, 0), 80)\n" ] } ], "source": [ - "set_verbose(2)\n", + "set_verbose(0)\n", "f=P.walkback(region=lambda v: add([v[i]**2 for i in range(len(v))])<2)\n", "print f\n", "set_verbose(0)" ] }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "L=range(10)" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 2, 3, 4, 5, 6, 7, 8, 9]\n", - "[2, 3, 4, 5, 6, 7, 8, 9]\n", - "[3, 4, 5, 6, 7, 8, 9]\n", - "[4, 5, 6, 7, 8, 9]\n", - "[5, 6, 7, 8, 9]\n", - "[6, 7, 8, 9]\n", - "[7, 8, 9]\n", - "[8, 9]\n", - "[9]\n", - "[]\n" - ] - } - ], - "source": [ - "while L:\n", - " L.pop(0)\n", - " print L" - ] - }, { "cell_type": "code", "execution_count": null, diff --git a/wbtl.ipynb b/wbtl.ipynb new file mode 100644 index 0000000..af8f701 --- /dev/null +++ b/wbtl.ipynb @@ -0,0 +1,126 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%load_ext sage" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%attach wbtl.py" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "13686" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "N = 10\n", + "L = 100\n", + "cost = random_vector(ZZ, N, 50, 100)\n", + "def R(N): return random_vector(ZZ, N, -2, 20)\n", + "P = R(N)\n", + "T = [R(N) for t in range(L)]\n", + "Cost_so_far = 2*abs(fast_dot(cost, P))\n", + "Cost_so_far" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " " + ] + } + ], + "source": [ + "%prun W=list(worthy_children(P, T, cost, Cost_so_far))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "32" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(W)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/wbtl.py b/wbtl.py new file mode 100755 index 0000000..1434a0d --- /dev/null +++ b/wbtl.py @@ -0,0 +1,118 @@ +#!/usr/bin/env sage -python +# encoding: utf-8 + +""" +Algorithms for computing test sets of Integer Programming problems. + +# ============================================== +# = This is ongoing work by J. Soto y JM Ucha. = +# ============================================== + +This file implements the algorithm walk back, then look. + +""" + +import operator +import itertools +from sage.all import * + + + + +def fast_add(l,m): + """ + Fast addition of two lists, as per + + http://stackoverflow.com/questions/18713321/element-wise-addition-of-2-lists-in-python + """ + # assert(len(l)==len(m)) + return map(operator.add, l,m) + # Slower alternatives: + # return [a+b for a,b in zip(l,m)] + # return list(itertools.imap(operator.add, l,m)) + +def isgtz(l): + """Check whether l[i]>0 for all i.""" + return all((li>0 for li in l)) + +def isgetz(l): + """Check whether l[i]>=0 for all i.""" + return all(li>=0 for li in l) + +def fast_dot(c,x): + """Quickly compute the scalar product c*x""" + # assert(len(c)==len(x)) + return add(itertools.imap(operator.mul, c,x)) + # To test: + # return add(map(operator.mul, c,x)) + # Slower alternative + # return add(ci*xi for ci,xi in zip(c,x)) + + +def worthy_children(P, T, cost, Oc=infinity): + """ + Find all children of point P from test set T, such that + 1. They are positive. + 2. Their cost is strictly less than the cost at the optimun so far, Oc. (Oc is the Optimum cost, not the optimum point itself.) + """ + for t in T: + candidate = fast_add(P,t) + if isgetz(candidate) and fast_dot(cost, candidate)<=Oc: + yield candidate + +def only_new(New, Cache): + """ + Check for each element of New whether it already belongs to cache. + Return a generator of elements not in the Cache, and update Cache. + + """ + for P in New: + if P not in Cache: + Cache.append(P) + yield P + +def add_to_V(current, T, c, best_cost_Omega, V, cached): + for v in worthy_children(current, T, c, best_cost_Omega): + if v not in cached: + cached.append(v) + V.append(v) + + +def walk_back_and_look_behing(P, T, Omega, c, A, b): + """ + Implement the walk back and look behind algorithm for the problem + min cx + st Ax=b + x in RegionOmega + with the given test set T, optimal point P for the linear problem, and non-linear region function indicator Omega. That is, x in RegionOmega == True if and only if Omega(x)==True + """ + best_cost_Omega = infinity + V = list() + S = list() + + if Omega(P): + S = [P] + else: + V = list(worthy_children(P, T, c)) + + cached = V[:] # shallow copy + while V: + current = V.pop() # 0 = first, nothing = last. + current_cost = fast_dot(c, current) + if Omega(current): + if current_cost < best_cost_Omega: + S = [current] + best_cost_Omega = current_cost + # elif current_cost == best_cost_Omega: + else: # worthy_children() only gives points with cost <= thatn best_cost_Omega + S.append(current) + enlarge = True + else: + enlarge = True + if enlarge: + # V += list(only_new(worthy_children(current, T, c, best_cost_Omega), cached)) + add_to_V(current, T, c, best_cost_Omega, V, cached) + enlarge = False + return S + + From 5735f9d600bcfad994f3aeed0ea5ccbfde2d3835 Mon Sep 17 00:00:00 2001 From: anteprandium Date: Wed, 23 Mar 2016 20:01:53 +0100 Subject: [PATCH 05/15] added doctests --- wbtl.ipynb | 84 +++++++++++++++++++++++++++++++++--------------- wbtl.py | 94 +++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 127 insertions(+), 51 deletions(-) diff --git a/wbtl.ipynb b/wbtl.ipynb index af8f701..3fb6d3e 100644 --- a/wbtl.ipynb +++ b/wbtl.ipynb @@ -2,18 +2,27 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 6, "metadata": { "collapsed": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The sage extension is already loaded. To reload it, use:\n", + " %reload_ext sage\n" + ] + } + ], "source": [ "%load_ext sage" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 134, "metadata": { "collapsed": false }, @@ -24,7 +33,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 135, "metadata": { "collapsed": false }, @@ -32,17 +41,17 @@ { "data": { "text/plain": [ - "13686" + "127740" ] }, - "execution_count": 3, + "execution_count": 135, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "N = 10\n", - "L = 100\n", + "N = 100\n", + "L = 100000\n", "cost = random_vector(ZZ, N, 50, 100)\n", "def R(N): return random_vector(ZZ, N, -2, 20)\n", "P = R(N)\n", @@ -53,7 +62,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 136, "metadata": { "collapsed": false }, @@ -72,25 +81,48 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": true }, - "outputs": [ - { - "data": { - "text/plain": [ - "32" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(W)" - ] + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] }, { "cell_type": "code", diff --git a/wbtl.py b/wbtl.py index 1434a0d..bd4167d 100755 --- a/wbtl.py +++ b/wbtl.py @@ -8,12 +8,12 @@ # = This is ongoing work by J. Soto y JM Ucha. = # ============================================== -This file implements the algorithm walk back, then look. +This file implements the algorithm “walk back, then look”. """ -import operator -import itertools +# import operator # not needed anymore +# import itertools # not needed anymore from sage.all import * @@ -21,39 +21,81 @@ def fast_add(l,m): """ - Fast addition of two lists, as per + Fast addition of two lists. First versions used ideas in + + http://stackoverflow.com/questions/18713321/element-wise-addition-of-2-lists-in-python + + using, essentially, + + return map(operator.add, l,m) + + Slower alternatives: + + return [a+b for a,b in zip(l,m)] + return list(itertools.imap(operator.add, l,m)) + + Turns out, fastest is just to wrap Sage's addition. Can't reinvent the wheel, after all. + + >>> fast_add([],[]) + () + + >>> fast_add([1,2],[1]) + Traceback (most recent call last): + ... + TypeError: unsupported operand parent(s) for '+': 'Ambient free module of rank 2 over the principal ideal domain Integer Ring' and 'Ambient free module of rank 1 over the principal ideal domain Integer Ring' + + + Caveat: returns a `vector`; not a `list`. + + >>> fast_add(10000*[1],10000*[3]) == vector(ZZ,10000*[4]) + True + - http://stackoverflow.com/questions/18713321/element-wise-addition-of-2-lists-in-python """ - # assert(len(l)==len(m)) - return map(operator.add, l,m) - # Slower alternatives: - # return [a+b for a,b in zip(l,m)] - # return list(itertools.imap(operator.add, l,m)) - -def isgtz(l): - """Check whether l[i]>0 for all i.""" - return all((li>0 for li in l)) + return vector(ZZ,l)+vector(ZZ,m) + +# def isgtz(l): +# """Check whether l[i]>0 for all i.""" +# return all(li>0 for li in l) def isgetz(l): - """Check whether l[i]>=0 for all i.""" + """ + Given a list or vector `l`, return `True` if all its components are greater or equal than 0. Uses a generator and `all` for speed. + + >>> isgetz(1000*[1]) + True + >>> isgetz(1000*[1]+[-1]) + False + + + On the empty list it returns `True`. + >>> isgetz([]) + True + + """ return all(li>=0 for li in l) def fast_dot(c,x): - """Quickly compute the scalar product c*x""" - # assert(len(c)==len(x)) - return add(itertools.imap(operator.mul, c,x)) - # To test: - # return add(map(operator.mul, c,x)) - # Slower alternative - # return add(ci*xi for ci,xi in zip(c,x)) + """ + Quickly compute the scalar product `c*x`. + + First versions used some iterators ideas: + + return add(itertools.imap(operator.mul, c,x)) + return add(map(operator.mul, c,x)) + return add(ci*xi for ci,xi in zip(c,x)) + + but it turns out the fastest is to use Sage's vectors. + """ + return vector(ZZ,c)*vector(ZZ,x) def worthy_children(P, T, cost, Oc=infinity): """ Find all children of point P from test set T, such that 1. They are positive. - 2. Their cost is strictly less than the cost at the optimun so far, Oc. (Oc is the Optimum cost, not the optimum point itself.) + 2. Their cost is strictly less than the cost at the optimum so far, Oc. (Oc is the Optimum cost, not the optimum point itself.) + 3. Are feasible? """ for t in T: candidate = fast_add(P,t) @@ -78,7 +120,7 @@ def add_to_V(current, T, c, best_cost_Omega, V, cached): V.append(v) -def walk_back_and_look_behing(P, T, Omega, c, A, b): +def walk_back_and_look_behind(P, T, Omega, c, A, b): """ Implement the walk back and look behind algorithm for the problem min cx @@ -115,4 +157,6 @@ def walk_back_and_look_behing(P, T, Omega, c, A, b): enlarge = False return S - +if __name__ == '__main__': + import doctest + doctest.testmod() \ No newline at end of file From c589c35fe9a97cca4f23cc86400cb33906474cdd Mon Sep 17 00:00:00 2001 From: anteprandium Date: Wed, 8 Mar 2017 14:04:21 +0100 Subject: [PATCH 06/15] trunc1st --- truncated.ipynb | 430 ++++++++++++++++++++++++++++++++++++++++++++++++ truncated.py | 285 ++++++++++++++++++++++++++++++++ 2 files changed, 715 insertions(+) create mode 100644 truncated.ipynb create mode 100755 truncated.py diff --git a/truncated.ipynb b/truncated.ipynb new file mode 100644 index 0000000..81b531c --- /dev/null +++ b/truncated.ipynb @@ -0,0 +1,430 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 193, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "\n", + "def random_vvv(l,n):\n", + " return [vector(ZZ,[ZZ.random_element() for i in xrange(l)] ) for j in xrange(n)]\n", + "\n", + "#vvv = random_vvv(5000, 1000)\n", + "#yyy = random_vvv(5000, 1000)" + ] + }, + { + "cell_type": "code", + "execution_count": 196, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "load(\"truncated.py\")" + ] + }, + { + "cell_type": "code", + "execution_count": 197, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3751 criterion 1, 0 criterion 2, 12603 reductions, 1593 non eligible, 459 equalities\n", + " " + ] + } + ], + "source": [ + "%%prun\n", + "vecs, g = bubu(A,b,c,u)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 198, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "169" + ] + }, + "execution_count": 198, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(vecs)" + ] + }, + { + "cell_type": "code", + "execution_count": 199, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "23 (1, 0, 0, 0, 0, 0, 0) True (3, 4, 5) True\n", + "15 (0, 1, 0, 0, 0, 0, 0) True (1, 5, 6) True\n", + "6 (0, 0, 1, 0, 0, 0, 0) True (11, 0, 1) True\n", + "7 (0, 0, 0, 1, 0, 0, 0) True (2, 1, 9) True\n", + "1 (0, 0, 0, 0, 1, 0, 0) True (3, 7, 2) True\n", + "53 (0, 0, 0, 0, 0, 1, 0) True (5, 4, 3) True\n", + "4 (0, 0, 0, 0, 0, 0, 1) True (3, 6, 3) True\n", + "49 (0, 0, 0, 0, 0, 1, -1) True (2, -2, 0) True\n", + "45 (0, 0, 0, 0, 0, 1, -2) True (-1, -8, -3) True\n", + "48 (0, 0, 0, 0, -1, 1, -1) True (-1, -9, -2) True\n", + "3 (0, 0, 0, 0, -1, 0, 1) True (0, -1, 1) True\n", + "2 (0, 0, 0, 0, -2, 0, 1) True (-3, -8, -1) True\n", + "4 (0, 0, 0, 1, 1, 0, -1) True (2, 2, 8) True\n", + "3 (0, 0, 0, 1, 0, 0, -1) True (-1, -5, 6) True\n", + "0 (0, 0, 0, -1, -1, 0, 2) True (1, 4, -5) True\n", + "2 (0, 0, 0, 1, -1, 0, -1) True (-4, -12, 4) True\n", + "1 (0, 0, 0, -1, 0, 0, 2) True (4, 11, -3) True\n", + "1 (0, 0, 0, 1, -2, 0, -1) True (-7, -19, 2) True\n", + "47 (0, 0, 0, -1, 1, 1, 0) True (6, 10, -4) True\n", + "46 (0, 0, 0, -1, 0, 1, 0) True (3, 3, -6) True\n", + "45 (0, 0, 0, -1, -1, 1, 0) True (0, -4, -8) True\n", + "6 (0, 0, 0, 1, -1, 0, 0) True (-1, -6, 7) True\n", + "39 (0, 0, 0, -2, 0, 1, 0) True (1, 2, -15) True\n", + "42 (0, 0, 0, -1, 0, 1, -1) True (0, -3, -9) True\n", + "32 (0, 0, 0, -3, 0, 1, 0) True (-1, 1, -24) True\n", + "25 (0, 0, 0, -4, 0, 1, 0) True (-3, 0, -33) True\n", + "24 (0, -1, 0, -2, 0, 1, 0) True (0, -3, -21) True\n", + "1 (0, 1, 0, -2, 0, 0, 0) True (-3, 3, -12) True\n", + "23 (0, -2, 0, 0, 0, 1, 0) True (3, -6, -9) True\n", + "8 (0, 1, 0, -1, 0, 0, 0) True (-1, 4, -3) True\n", + "16 (0, -2, 0, -1, 0, 1, 0) True (1, -7, -18) True\n", + "8 (0, -3, 0, 0, 0, 1, 0) True (2, -11, -15) True\n", + "26 (0, 2, 0, 0, 0, 0, -1) True (-1, 4, 9) True\n", + "7 (0, 4, 0, 0, 0, -1, 0) True (-1, 16, 21) True\n", + "19 (0, -2, 0, 0, 0, 1, -1) True (0, -12, -12) True\n", + "11 (0, 1, 0, 0, 0, 0, -1) True (-2, -1, 3) True\n", + "31 (0, -1, 0, -1, 0, 1, 0) True (2, -2, -12) True\n", + "1 (0, -3, 0, -1, 0, 1, 0) True (0, -12, -24) True\n", + "44 (0, 3, 0, 0, -1, 0, 0) True (0, 8, 16) True\n", + "37 (0, -1, 0, 0, -1, 1, 0) True (1, -8, -5) True\n", + "22 (0, -2, 0, 0, -1, 1, 0) True (0, -13, -11) True\n", + "14 (0, 1, 0, 0, -1, 0, 0) True (-2, -2, 4) True\n", + "10 (0, 1, 0, 0, -1, 0, -1) True (-5, -8, 1) True\n", + "38 (0, -1, 0, 0, 0, 1, 0) True (4, -1, -3) True\n", + "13 (0, -1, 0, 4, 0, 0, 0) True (7, -1, 30) True\n", + "18 (0, 2, 0, -1, -1, 0, -1) True (-6, -4, -2) True\n", + "4 (0, 1, 0, -1, 0, 0, -1) True (-4, -2, -6) True\n", + "6 (0, -1, 0, 3, 0, 0, 0) True (5, -2, 21) True\n", + "8 (0, 2, 0, -3, -1, 0, 0) True (-7, 0, -17) True\n", + "15 (0, 2, 0, -2, -1, 0, 0) True (-5, 1, -8) True\n", + "11 (0, 1, 0, -1, -1, 0, 1) True (-1, 3, -2) True\n", + "7 (0, 1, 0, 0, 0, 0, -2) True (-5, -7, 0) True\n", + "7 (0, 1, 0, -1, -1, 0, 0) True (-4, -3, -5) True\n", + "34 (0, -1, 0, 0, 0, 1, -1) True (1, -7, -6) True\n", + "43 (0, 0, -1, 0, 0, 1, -1) True (-9, -2, -1) True\n", + "9 (0, 1, -1, 0, 0, 0, 0) True (-10, 5, 5) True\n", + "2 (0, 0, -1, 1, 1, 0, 0) True (-6, 8, 10) True\n", + "1 (0, 0, 1, 0, -1, 0, -1) True (5, -13, -4) True\n", + "42 (0, 0, -2, 0, 1, 1, 0) True (-14, 11, 3) True\n", + "40 (0, 0, -1, -1, 0, 1, 0) True (-8, 3, -7) True\n", + "2 (0, 0, 1, 0, 0, 0, -1) True (8, -6, -2) True\n", + "41 (0, 0, -2, 0, 0, 1, 0) True (-17, 4, 1) True\n", + "1 (0, 0, -1, 1, 0, 0, 0) True (-9, 1, 8) True\n", + "5 (0, 0, 1, 0, -1, 0, 0) True (8, -7, -1) True\n", + "32 (0, -1, -1, 0, 0, 1, 0) True (-7, -1, -4) True\n", + "7 (0, -1, -1, 4, 0, 0, 0) True (-4, -1, 29) True\n", + "0 (0, -1, -1, 3, 0, 0, 0) True (-6, -2, 20) True\n", + "6 (0, 1, 2, -3, 0, 0, 0) True (17, 2, -19) True\n", + "5 (0, 0, 2, -1, 0, 0, 0) True (20, -1, -7) True\n", + "0 (0, 0, -1, 1, -1, 0, 0) True (-12, -6, 6) True\n", + "8 (0, 1, -1, 0, -1, 0, 0) True (-13, -2, 3) True\n", + "3 (0, -1, 3, 0, 0, 0, 0) True (32, -5, -3) False\n", + "1 (0, -1, 2, 0, 0, 0, 1) True (24, 1, -1) True\n", + "4 (0, 1, -1, 0, -1, 0, -1) True (-16, -8, 0) True\n", + "2 (0, 1, -2, 0, -1, 0, 0) True (-24, -2, 2) True\n", + "3 (0, 1, -2, 0, 0, 0, 0) True (-21, 5, 4) True\n", + "5 (0, 1, -1, 0, 0, 0, -1) True (-13, -1, 2) True\n", + "3 (0, 0, 1, -1, 0, 0, 1) True (12, 5, -5) True\n", + "35 (0, 0, -3, 0, 0, 1, 0) True (-28, 4, 0) True\n", + "46 (0, 0, -1, 0, -1, 1, 0) True (-9, -3, 0) True\n", + "4 (0, 0, 1, 0, -2, 0, 0) True (5, -14, -3) True\n", + "9 (0, 1, 0, 0, -2, 0, -1) True (-8, -15, -1) True\n", + "1 (0, 1, -2, 0, -2, 0, 0) True (-27, -9, 0) True\n", + "12 (0, 1, 0, 0, -3, 0, 0) True (-8, -16, 0) True\n", + "7 (0, 1, -1, 0, -2, 0, 0) True (-16, -9, 1) True\n", + "13 (0, 1, 0, 0, -2, 0, 0) True (-5, -9, 2) True\n", + "51 (0, 0, 0, 0, -2, 1, 0) True (-1, -10, -1) True\n", + "47 (0, 0, -1, 0, 0, 1, 0) True (-6, 4, 2) True\n", + "2 (0, 0, -1, 0, 0, 0, 2) True (-5, 12, 5) True\n", + "0 (0, 0, -1, 0, 2, 0, 1) True (-2, 20, 6) True\n", + "3 (0, 0, 1, 0, -3, 0, 0) True (2, -21, -5) True\n", + "0 (0, 0, 0, -1, 3, 0, 1) True (10, 26, 0) True\n", + "5 (0, 0, 1, 1, -4, 0, -1) True (-2, -33, -1) True\n", + "8 (0, 0, 1, 1, -5, 0, 0) True (-2, -34, 0) True\n", + "5 (0, 0, 0, 1, -2, 0, 0) True (-4, -13, 5) True\n", + "3 (0, 0, 0, 1, -4, 0, 0) True (-10, -27, 1) True\n", + "2 (0, 0, 1, 1, -3, 0, -2) True (-2, -32, -2) True\n", + "2 (0, 0, 1, 0, -4, 0, 0) True (-1, -28, -7) True\n", + "1 (0, 0, 1, 1, 0, 0, -3) True (4, -17, 1) True\n", + "0 (0, 0, -1, -1, 1, 0, 3) True (-1, 24, 1) True\n", + "0 (0, 0, -1, -2, 0, 0, 5) True (0, 28, -4) False\n", + "3 (0, 0, -1, -1, 0, 0, 4) True (-1, 23, 2) True\n", + "3 (0, 0, 1, 1, -2, 0, -2) True (1, -25, 0) True\n", + "33 (0, 0, -1, -2, 0, 1, 0) True (-10, 2, -16) True\n", + "23 (-1, 0, 0, -1, 0, 1, 0) True (0, -1, -11) True\n", + "10 (1, 0, -1, -1, 0, 0, 0) True (-10, 3, -5) True\n", + "13 (-2, 0, 1, 0, 0, 1, 0) True (10, -4, -6) True\n", + "16 (1, 0, 0, -1, 0, 0, 0) True (1, 3, -4) True\n", + "7 (-2, 0, 0, 0, 0, 1, 0) True (-1, -4, -7) True\n", + "44 (2, 0, 0, 0, -2, 0, 0) True (0, -6, 6) True\n", + "22 (1, 0, 0, 0, -1, 0, 0) True (0, -3, 3) True\n", + "19 (1, 0, 1, 1, -1, 0, -4) True (1, -26, 1) True\n", + "18 (1, 0, 0, 0, -1, 0, -1) True (-3, -9, 0) True\n", + "15 (1, 0, 0, 0, 0, 0, -2) True (-3, -8, -1) True\n", + "4 (0, 0, 1, 1, -1, 0, -2) True (4, -18, 2) True\n", + "25 (-1, 0, -1, 0, 1, 1, 0) True (-6, 7, -1) True\n", + "28 (-1, 0, -1, 0, 0, 1, 1) True (-6, 6, 0) True\n", + "21 (1, 0, -1, 0, 0, 0, 1) True (-5, 10, 7) True\n", + "63 (3, 0, -1, 0, 0, 0, 0) True (-2, 12, 14) True\n", + "42 (2, 0, 0, 0, 0, 0, -1) True (3, 2, 7) True\n", + "19 (1, 0, 0, 0, 0, 0, -1) True (0, -2, 2) True\n", + "20 (1, 0, 0, 0, -3, 0, 0) True (-6, -17, -1) True\n", + "20 (1, 0, -1, 0, 3, 0, 0) True (1, 25, 10) True\n", + "21 (1, 0, 0, 0, -2, 0, 0) True (-3, -10, 1) True\n", + "42 (2, 0, -1, 0, 2, 0, 0) True (1, 22, 13) True\n", + "30 (-1, 0, 0, 0, 0, 1, 0) True (2, 0, -2) True\n", + "41 (2, 0, -1, 0, 1, 0, 0) True (-2, 15, 11) True\n", + "18 (1, 0, -1, 0, 1, 0, 0) True (-5, 11, 6) True\n", + "17 (1, 0, -1, 0, 0, 0, 0) True (-8, 4, 4) True\n", + "15 (1, 0, -1, 0, -2, 0, 0) True (-14, -10, 0) True\n", + "2 (0, 0, -1, -1, -1, 0, 4) True (-4, 16, 0) True\n", + "19 (1, 0, 0, -1, -1, 0, 1) True (1, 2, -3) True\n", + "38 (2, 0, 0, -1, -1, 0, 0) True (1, 0, -1) True\n", + "15 (1, 0, 0, -1, -1, 0, 0) True (-2, -4, -6) True\n", + "24 (-1, 0, -1, 0, 0, 1, 0) True (-9, 0, -3) True\n", + "29 (-1, 0, 0, 0, -1, 1, 0) True (-1, -7, -4) True\n", + "26 (-1, 0, 0, 0, 0, 1, -1) True (-1, -6, -5) True\n", + "13 (1, 0, -1, 0, 0, 0, -1) True (-11, -2, 1) True\n", + "5 (0, 0, 1, 1, 0, 0, -2) True (7, -11, 4) True\n", + "3 (1, -1, -1, 0, 1, 0, 0) True (-6, 6, 0) True\n", + "4 (1, -1, 0, 0, 0, 0, -1) True (-1, -7, -4) True\n", + "2 (1, -1, -1, 0, 0, 0, 0) True (-9, -1, -2) True\n", + "4 (0, 0, 0, 1, -3, 0, 0) True (-7, -20, 3) True\n", + "2 (0, 0, 1, -1, 3, 0, 0) True (18, 20, -2) True\n", + "10 (1, 0, -2, 0, -1, 0, 0) True (-22, -3, 1) True\n", + "16 (1, 0, -1, 0, -1, 0, 0) True (-11, -3, 2) True\n", + "9 (1, -1, 0, 0, 1, 0, 0) True (5, 6, 1) True\n", + "8 (1, -1, 0, 0, 0, 0, 0) True (2, -1, -1) True\n", + "7 (1, 0, -2, 0, 0, 0, -1) True (-22, -2, 0) True\n", + "4 (1, 0, -3, 0, -1, 0, 0) True (-33, -3, 0) True\n", + "11 (1, 0, -2, 0, 0, 0, 0) True (-19, 4, 3) True\n", + "5 (1, 0, -3, 0, 0, 0, 0) True (-30, 4, 2) True\n", + "1 (-1, 0, 4, 0, 0, 0, 0) True (41, -4, -1) False\n", + "9 (1, 0, 0, -2, 0, 0, 0) True (-1, 2, -13) True\n", + "12 (1, 0, 0, -1, 0, 0, -1) True (-2, -3, -7) True\n", + "8 (1, 0, 1, -3, 0, 0, 0) True (8, 1, -21) True\n", + "2 (1, 0, 0, -3, 0, 0, 0) True (-3, 1, -22) True\n", + "1 (1, -1, 0, -1, 0, 0, 0) True (0, -2, -10) True\n", + "1 (1, 0, 1, -4, 0, 0, 0) True (6, 0, -30) True\n", + "5 (-1, 0, 0, 4, 0, 0, 0) True (5, 0, 31) True\n", + "4 (-2, 0, -1, 8, 0, 0, 0) True (-1, 0, 61) False\n", + "0 (-1, -2, 0, 0, 0, 1, 0) True (0, -10, -14) True\n", + "7 (-1, 2, 0, 0, 0, 0, 0) True (-1, 6, 7) True\n", + "7 (1, -1, 0, 0, -1, 0, 0) True (-1, -8, -3) True\n", + "15 (-1, -1, 0, 0, 0, 1, 0) True (1, -5, -8) True\n", + "1 (0, 0, 1, -1, 2, 0, 0) True (15, 13, -4) True\n", + "2 (0, 0, 0, 1, -5, 0, 0) True (-13, -34, -1) True\n", + "52 (0, 0, 0, 0, -1, 1, 0) True (2, -3, 1) True\n", + "6 (0, 0, 1, 1, -3, 0, -1) True (1, -26, 1) True\n" + ] + } + ], + "source": [ + "for i in vecs: print c*i, i, let(i,u), A*i, let(A*i,b)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, False, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, False, False, True, True, False, False, True, True, False, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, False, False, True, True, True, True, True, True, True, True, True, False, True, True, True, False, True, True, True, True]\n" + ] + } + ], + "source": [ + "print g.eligible" + ] + }, + { + "cell_type": "code", + "execution_count": 204, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "load(\"truncated.py\")" + ] + }, + { + "cell_type": "code", + "execution_count": 205, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3084 criterion 1, 0 criterion 2, 4836 reductions, 6792 non eligible, 349 equalities\n", + " " + ] + } + ], + "source": [ + "%%prun\n", + "\n", + "A = matrix(ZZ, [[3,1,11,2,3,5,3], [4, 5, 0, 1, 7,4, 6], [5,6,1,9,2,3,3]])\n", + "c = vector(ZZ, [23,15,6,7,1,53,4])\n", + "b = vector(ZZ, [31,27,38])\n", + "u = vector(ZZ, 7*[1])\n", + "vects, g = bubu(A,b,c,u)" + ] + }, + { + "cell_type": "code", + "execution_count": 206, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "153" + ] + }, + "execution_count": 206, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(vects)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 207, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[True, True, True, True, True, True, True, True, False, True, True, True, True, True, True, True, False, False, False, True, True, False, True, True, False, True, False, False, True, True, False, True, True, False, False, False, False, False, False, True, False, False, False, False, True, False, False, True, True, False, False, False, False, False, False, False, True, True, True, False, True, True, True, False, False, True, False, True, False, False, False, True, True, False, False, True, True, True, True, True, True, True, True, False, False, True, True, True, False, True, True, True, True, True, True, True, False, True, True, True, True, False, False, True, True, False, False, True, True, True, True, True, False, True, False, False, True, False, False, False, False, False, True, False, True, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, True, False, False, False, False]\n" + ] + } + ], + "source": [ + "print g.eligible" + ] + }, + { + "cell_type": "code", + "execution_count": 208, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "((1, 2, 0, 1, 0, 0, 0, 0, 1, 2, 0, 0, 0, 2, 0, 0, 9, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 3, 2, 247, 0, 0, 0, 0, 51, 0, 2, 1, 0, 0, 2, 2, 0, 4, 7, 0, 0, 0, 0, 0, 1, 1, 0, 3, 0, 0, 0, 0, 0, 4, 0, 7, 0, 0, 4, 0, 0, 3, 0, 0, 12, 2, 0, 0, 1, 6, 0, 1, 0, 10, 32, 0, 0, 0, 0, 0, 0, 2, 0, 1, 0, 3, 3, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 1, 1, 0, 0, 5, 0, 1, 10, 0, 0, 2, 0, 1, 1, 10, 0, 2, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 32, 0, 1, 0, 1, 3, 0, 0, 0, 1, 0, 0, 9, 10, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 4, 0, 1, 5, 0, 0, 1, 0, 2, 1, 0, 2, 2, 0, 0, 0, 0, 3, 1, 2, 1, 0, 1, 1, 0, 2, 0, 1, 0, 1, 0, 0, 0, 16, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 13, 0, 1, 0, 0, 1, 0, 1, 0, 7, 1, 0, 0, 0, 0, 0, 1, 1, 2, 2, 0, 0, 0, 43, 5, 7, 7, 0, 1, 0, 4, 1, 0, 5, 1, 0, 0, 2, 2, 0, 0, 0, 4, 1, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 2, 0, 2, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 3, 0, 0, 0, 10, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 3, 2, 0, 0, 1, 1, 2, 0, 0, 0, 1, 0, 0, 2, 1, 2, 0, 1, 1, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0, 4, 0, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 3, 0, 0, 0, 1, 0, 4, 0, 1, 0, 0, 1, 0, 1, 0, 6, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 0, 1, 13, 0, 0, 5, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 10, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 6, 0, 0, 1, 0, 0, 0, 2, 1, 0, 0, 2, 0, 1, 0, 1),\n", + " (0, 0, 1, 0, 1, 0, 2, 3, 0, 0, 3, 0, 0, 0, 53, 1, 0, 14, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 2, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 14, 0, 3, 1, 0, 0, 3, 0, 2, 0, 0, 0, 0, 0, 0, 3, 0, 0, 1, 1, 0, 0, 3, 0, 1, 0, 0, 0, 0, 5, 0, 3, 0, 0, 1, 0, 28, 0, 0, 0, 14, 10, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 3, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 2, 2, 1, 1, 0, 3, 1, 2, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 3, 3, 2, 0, 1, 0, 0, 0, 0, 1, 1, 0, 2, 0, 0, 3, 0, 0, 0, 1, 7, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 66, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 9, 4, 10, 0, 8, 0, 0, 0, 0, 0, 0, 1, 0, 0, 5, 1, 0, 0, 0, 11, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 135, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 2, 8, 0, 0, 1, 3, 0, 0, 0, 1, 0, 0, 2, 7, 0, 1, 0, 1, 0, 0, 1, 8, 1, 3, 1, 1, 0, 2, 4, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 4, 1, 1, 0, 0, 1, 1, 0, 0, 2, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 1, 0, 0, 3, 47, 1, 1, 0, 0, 0, 1, 1, 1, 1, 6, 0, 0, 7, 9, 0, 1, 0, 2, 1, 0, 0, 1, 0, 2, 6, 0, 28, 0, 0, 1, 0, 0, 3, 2, 3, 5, 9, 1, 1, 1, 1, 1, 0, 1, 4, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 111, 2, 1, 1, 2, 4, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 8, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 3, 5, 0, 1, 0, 0, 0, 0, 0, 1, 3, 2, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 10, 0))" + ] + }, + "execution_count": 208, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pm_split(vvv[0])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "SageMath 7.5.1", + "language": "", + "name": "sagemath" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.13" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/truncated.py b/truncated.py new file mode 100755 index 0000000..f638441 --- /dev/null +++ b/truncated.py @@ -0,0 +1,285 @@ +#!/usr/bin/env python + +from collections import deque + + + + +def getz(v): + """Check if v is greater or equal than zero, component-wise.""" + # return all(vi>=0 for vi in v) #(Slower by a factor of 2) + for vi in v: + if vi<0: return False + return True + +def isz(v): + """Check if v is zero. Slightly faster than .is_zero()""" + # return all(vi>=0 for vi in v) #(Slower by a factor of 2) + for vi in v: + if vi!=0: return False + return True + + +def let(a,b): + "True if and only if a is less or equal than b. Faster than zipping lists by a factor of 100" + for i in xrange(len(a)): + if a[i]>b[i]: + return False + return True + + + +def standard_basis(n): + return identity_matrix(ZZ,n).rows() + + + +# def pm_split3(v): +# "Split a vector `v` into its positive and negative part, so that $v=v^-v^-$." +# up = [] +# um = [] +# for a in v: +# if a>=0: +# up.append(a) +# um.append(0) +# else: +# up.append(0) +# um.append(-a) +# return vector(ZZ,up), vector(ZZ,um) +# +# +# def pm_split2(v): +# """ slightly faster than pm_split3""" +# l = len(v) +# up = [0]*l +# um = [0]*l +# for i in xrange(l): +# if v[i]>0: +# up[i]=v[i] +# else: +# um[i]=-v[i] +# return vector(ZZ,up), vector(ZZ,um) +# +def pm_split(v): + """ slightly faster than pm_split2""" + l = len(v) + up = l*[0] + um = l*[0] + for i,a in enumerate(v): + if a>0: + up[i]=a + else: + um[i]=-a + return vector(ZZ,up), vector(ZZ,um) + + +class PartialBasis(object): + """docstring for PartialBasis""" + def __init__(self, A, c, b, u): + super(PartialBasis, self).__init__() + self.n = A.dimensions()[1] + self.A = A + self.c = c + self.b = b + self.u = u + self.vectors = [] + self.cv = [] + self.vecp = [] + self.vecn = [] + self.pairs = [] + self.psupp = [] + self.Avp = [] + self.Avm = [] + self.eligible = [] + for e in identity_matrix(ZZ,self.n).rows(): + self.add_element(e) + + def add_element(self, v, check=True): + """ + add element e to partial basis, update critical pairs to be computed, + and precompute as much stuff as possible for reduction. + """ + cv = c*v + e = v if cv>0 else -v # this makes sure that e^+ >_c e^-. + l = len(self.vectors) + self.vectors.append(e) + if l: # true if this is not the first vector + for i in xrange(l): + self.pairs.append((i,l)) + ep, em = pm_split(e) + self.vecp.append(ep) + self.vecn.append(em) + self.psupp.append(set(e.support())) + Avp, Avm = pm_split(A*e) + self.Avp.append(Avp) + self.Avm.append(Avm) + self.cv.append(abs(cv)) + self.eligible.append(let(ep,self.u) and let(em,self.u) and let(A*ep,self.b) and let(A*em,self.b) ) + + + def criterion_1(self, i, j): + """True if (i,j) is skipabble.""" + t = len(self.psupp[i].intersection(self.psupp[j]))==0 + return t + + def max(self, i, j): + """docstring for max""" + return vector(ZZ, [max(self.vecp[i][k],self.vecp[j][k]) for k in xrange(self.n)]) + + def criterion_2(self, i, j): + """Gebauer and Möller""" + # it is assumed i200: break + i, j = g.pop() + if g.criterion_1(i,j): + c1 += 1 + next + # if g.criterion_2(i,j): + # c2 += 1 + # next + + + cv = g.cv[i] + cw = g.cv[j] + if cv == cw: + equ +=1 + next + elif cw < cv: + i, j = j, i + # At this point, cv < cw. + # 2.2.1 + if g.eligible[i]: + rx +=1 + r = g.vectors[j]-g.vectors[i] + c = g.reduce(r) + if not isz(c): + g.add_element(c) + else: + elig += 1 + next + + print "%s criterion 1, %s criterion 2, %s reductions, %s non eligible, %s equalities" % (c1, c2, rx, elig, equ) + return g.vectors, g + + + + +A = matrix(ZZ, [[3,1,11,2,3,5,3], [4, 5, 0, 1, 7,4, 6], [5,6,1,9,2,3,3]]) +c = vector(ZZ, [23,15,6,7,1,53,4]) +b = vector(ZZ, [31,27,38]) +u = vector(ZZ, 7*[38]) + \ No newline at end of file From d03a0d3ff7895b9520869da732a1f299335ed353 Mon Sep 17 00:00:00 2001 From: anteprandium Date: Wed, 8 Mar 2017 15:42:47 +0100 Subject: [PATCH 07/15] changed eligibility --- truncated.ipynb | 130 +++++++++++++++++++++++++++++++++++++----------- truncated.py | 11 ++-- 2 files changed, 106 insertions(+), 35 deletions(-) diff --git a/truncated.ipynb b/truncated.ipynb index 81b531c..3e728ce 100644 --- a/truncated.ipynb +++ b/truncated.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 193, + "execution_count": 222, "metadata": { "collapsed": false }, @@ -12,13 +12,87 @@ "def random_vvv(l,n):\n", " return [vector(ZZ,[ZZ.random_element() for i in xrange(l)] ) for j in xrange(n)]\n", "\n", + "def random_lll(l,n):\n", + " return [ [ZZ.random_element() for i in xrange(l)] for j in xrange(n)]\n", + "\n", + "longitud = 500\n", + "numero = 100\n", + "\n", + "xxx = random_lll(longitud, numero)\n", + "yyy = random_lll(longitud, numero)\n", + "zzz = [vector(ZZ,z) for z in zzz]\n", + "ttt = [vector(ZZ,z) for z in yyy]\n", + "\n", "#vvv = random_vvv(5000, 1000)\n", "#yyy = random_vvv(5000, 1000)" ] }, { "cell_type": "code", - "execution_count": 196, + "execution_count": 232, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1000 loops, best of 3: 1.37 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit \n", + "for (e,v) in zip(zzz,ttt):\n", + " e*v" + ] + }, + { + "cell_type": "code", + "execution_count": 233, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100 loops, best of 3: 10.3 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "for (e,v) in zip(xxx,yyy):\n", + " dotprod(e,v)" + ] + }, + { + "cell_type": "code", + "execution_count": 234, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100 loops, best of 3: 10.5 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "for (e,v) in zip(zzz,ttt):\n", + " dotproduct(e,v)" + ] + }, + { + "cell_type": "code", + "execution_count": 231, "metadata": { "collapsed": false }, @@ -288,7 +362,7 @@ }, { "cell_type": "code", - "execution_count": 204, + "execution_count": 246, "metadata": { "collapsed": false }, @@ -299,7 +373,7 @@ }, { "cell_type": "code", - "execution_count": 205, + "execution_count": 250, "metadata": { "collapsed": false }, @@ -308,7 +382,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "3084 criterion 1, 0 criterion 2, 4836 reductions, 6792 non eligible, 349 equalities\n", + "787 criterion 1, 0 criterion 2, 1952 reductions, 974 non eligible, 52 equalities\n", " " ] } @@ -325,7 +399,7 @@ }, { "cell_type": "code", - "execution_count": 206, + "execution_count": 248, "metadata": { "collapsed": false }, @@ -333,10 +407,10 @@ { "data": { "text/plain": [ - "153" + "77" ] }, - "execution_count": 206, + "execution_count": 248, "metadata": {}, "output_type": "execute_result" } @@ -347,16 +421,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 249, "metadata": { "collapsed": false }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[(1, 0, 0, 0, 0, 0, 0), (0, 1, 0, 0, 0, 0, 0), (0, 0, 1, 0, 0, 0, 0), (0, 0, 0, 1, 0, 0, 0), (0, 0, 0, 0, 1, 0, 0), (0, 0, 0, 0, 0, 1, 0), (0, 0, 0, 0, 0, 0, 1), (0, 0, 0, 0, 0, 1, -1), (0, 0, 0, 0, -1, 1, -1), (0, 0, 0, -1, 0, 1, -1), (0, 0, 0, 1, -1, 0, 0), (0, 0, 0, 1, -1, 0, -1), (0, 0, 0, -1, 0, 1, 0), (0, 0, 0, 1, 0, 0, -1), (0, 0, 0, 0, -1, 0, 1), (0, 0, 1, 0, 1, 0, -1), (0, 0, -1, 1, -1, 0, 0), (0, 0, 1, -1, 0, 0, 1), (0, 0, -1, 0, 0, 1, -1), (0, 0, -1, -1, 0, 1, 0), (0, 0, 1, 0, -1, 0, 0), (0, 0, 1, 0, 0, 0, -1), (0, 0, -1, 1, 0, 0, 0), (0, 0, 1, 0, -1, 0, -1), (0, 0, -1, 0, 0, 1, 0), (0, 0, -1, 0, -1, 1, 0), (0, 0, 0, -1, -1, 1, 0), (0, -1, -1, 0, 0, 1, 0), (0, 1, 1, -1, -1, 0, 0), (0, 1, 0, -1, 0, 0, 1), (0, 1, 1, -1, 0, 0, 0), (0, 1, 0, -1, 1, 0, 0), (0, 1, 0, -1, 0, 0, 0), (0, -1, 0, 0, -1, 1, 0), (0, 1, -1, 0, 0, 0, 0), (0, -1, 0, -1, 0, 1, 0), (0, 1, 0, 0, -1, 0, 0), (0, 1, -1, 0, 0, 0, -1), (0, -1, 0, 0, 0, 1, 1), (0, 1, 0, -1, 0, 0, -1), (0, 1, 0, -1, -1, 0, 0), (0, -1, 0, 0, 0, 1, 0), (0, 1, -1, 0, -1, 0, 0), (0, 1, -1, 0, -1, 0, -1), (1, -1, 0, 0, 1, 0, 0), (-1, 0, 0, 0, -1, 1, 0), (-1, 0, 0, 0, 0, 1, 0), (1, -1, 0, 0, 0, 0, 0), (-1, 0, 0, -1, 0, 1, 0), (1, 0, -1, 0, 0, 0, -1), (1, -1, -1, 0, 1, 0, 0), (0, 1, 0, 0, -1, 0, -1), (1, 0, 0, 0, 0, 0, -1), (0, 1, 0, 0, 0, 0, -1), (1, -1, -1, 0, 0, 0, 0), (1, -1, 0, -1, 0, 0, 0), (-1, 0, -1, 1, 0, 1, 0), (1, 0, 0, -1, 0, 0, -1), (1, -1, 0, 0, 0, 0, -1), (-1, 0, -1, 0, 0, 1, 1), (1, 0, 0, 0, -1, 0, 0), (-1, -1, 0, 0, 0, 1, 0), (1, 0, 0, -1, 0, 0, 0), (1, -1, 0, 0, -1, 0, 0), (-1, 0, -1, 0, 1, 1, 0), (1, 0, 0, 0, -1, 0, -1), (1, 0, -1, 0, 0, 0, 0), (-1, 0, 0, 0, 0, 1, -1), (1, 0, 0, -1, -1, 0, 1), (1, 0, 0, -1, -1, 0, 0), (1, 0, -1, -1, 0, 0, 1), (1, 0, -1, -1, 1, 0, 0), (1, 0, -1, -1, 0, 0, 0), (-1, 0, -1, 0, 0, 1, 0), (1, 0, -1, 0, -1, 0, 0), (0, -1, 0, 0, 0, 1, -1), (0, 0, 0, 0, -1, 1, 0)]\n" + ] + } + ], + "source": [ + "print g.vectors" + ] }, { "cell_type": "code", - "execution_count": 207, + "execution_count": 238, "metadata": { "collapsed": false }, @@ -375,26 +459,12 @@ }, { "cell_type": "code", - "execution_count": 208, + "execution_count": null, "metadata": { - "collapsed": false + "collapsed": true }, - "outputs": [ - { - "data": { - "text/plain": [ - "((1, 2, 0, 1, 0, 0, 0, 0, 1, 2, 0, 0, 0, 2, 0, 0, 9, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 3, 2, 247, 0, 0, 0, 0, 51, 0, 2, 1, 0, 0, 2, 2, 0, 4, 7, 0, 0, 0, 0, 0, 1, 1, 0, 3, 0, 0, 0, 0, 0, 4, 0, 7, 0, 0, 4, 0, 0, 3, 0, 0, 12, 2, 0, 0, 1, 6, 0, 1, 0, 10, 32, 0, 0, 0, 0, 0, 0, 2, 0, 1, 0, 3, 3, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 1, 1, 0, 0, 5, 0, 1, 10, 0, 0, 2, 0, 1, 1, 10, 0, 2, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 32, 0, 1, 0, 1, 3, 0, 0, 0, 1, 0, 0, 9, 10, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 4, 0, 1, 5, 0, 0, 1, 0, 2, 1, 0, 2, 2, 0, 0, 0, 0, 3, 1, 2, 1, 0, 1, 1, 0, 2, 0, 1, 0, 1, 0, 0, 0, 16, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 13, 0, 1, 0, 0, 1, 0, 1, 0, 7, 1, 0, 0, 0, 0, 0, 1, 1, 2, 2, 0, 0, 0, 43, 5, 7, 7, 0, 1, 0, 4, 1, 0, 5, 1, 0, 0, 2, 2, 0, 0, 0, 4, 1, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 2, 0, 2, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 3, 0, 0, 0, 10, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 3, 2, 0, 0, 1, 1, 2, 0, 0, 0, 1, 0, 0, 2, 1, 2, 0, 1, 1, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0, 4, 0, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 3, 0, 0, 0, 1, 0, 4, 0, 1, 0, 0, 1, 0, 1, 0, 6, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 0, 1, 13, 0, 0, 5, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 10, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 6, 0, 0, 1, 0, 0, 0, 2, 1, 0, 0, 2, 0, 1, 0, 1),\n", - " (0, 0, 1, 0, 1, 0, 2, 3, 0, 0, 3, 0, 0, 0, 53, 1, 0, 14, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 2, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 14, 0, 3, 1, 0, 0, 3, 0, 2, 0, 0, 0, 0, 0, 0, 3, 0, 0, 1, 1, 0, 0, 3, 0, 1, 0, 0, 0, 0, 5, 0, 3, 0, 0, 1, 0, 28, 0, 0, 0, 14, 10, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 3, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 2, 2, 1, 1, 0, 3, 1, 2, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 3, 3, 2, 0, 1, 0, 0, 0, 0, 1, 1, 0, 2, 0, 0, 3, 0, 0, 0, 1, 7, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 66, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 9, 4, 10, 0, 8, 0, 0, 0, 0, 0, 0, 1, 0, 0, 5, 1, 0, 0, 0, 11, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 135, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 2, 8, 0, 0, 1, 3, 0, 0, 0, 1, 0, 0, 2, 7, 0, 1, 0, 1, 0, 0, 1, 8, 1, 3, 1, 1, 0, 2, 4, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 4, 1, 1, 0, 0, 1, 1, 0, 0, 2, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 1, 0, 0, 3, 47, 1, 1, 0, 0, 0, 1, 1, 1, 1, 6, 0, 0, 7, 9, 0, 1, 0, 2, 1, 0, 0, 1, 0, 2, 6, 0, 28, 0, 0, 1, 0, 0, 3, 2, 3, 5, 9, 1, 1, 1, 1, 1, 0, 1, 4, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 111, 2, 1, 1, 2, 4, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 8, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 3, 5, 0, 1, 0, 0, 0, 0, 0, 1, 3, 2, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 10, 0))" - ] - }, - "execution_count": 208, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "pm_split(vvv[0])" - ] + "outputs": [], + "source": [] }, { "cell_type": "code", diff --git a/truncated.py b/truncated.py index f638441..20feb63 100755 --- a/truncated.py +++ b/truncated.py @@ -3,8 +3,6 @@ from collections import deque - - def getz(v): """Check if v is greater or equal than zero, component-wise.""" # return all(vi>=0 for vi in v) #(Slower by a factor of 2) @@ -99,7 +97,7 @@ def add_element(self, v, check=True): add element e to partial basis, update critical pairs to be computed, and precompute as much stuff as possible for reduction. """ - cv = c*v + cv = self.c*v e = v if cv>0 else -v # this makes sure that e^+ >_c e^-. l = len(self.vectors) self.vectors.append(e) @@ -262,9 +260,12 @@ def bubu(A,b,c,u): i, j = j, i # At this point, cv < cw. # 2.2.1 - if g.eligible[i]: + #if g.eligible[i]: + r = g.vectors[j]-g.vectors[i] + rp,rm = pm_split(r) + if let(rp,u) and let(rm,u) and let(A*rp,b) and let(A*rm,b) : rx +=1 - r = g.vectors[j]-g.vectors[i] + # r = g.vectors[j]-g.vectors[i] c = g.reduce(r) if not isz(c): g.add_element(c) From ca1c5327e44dcfd3db9749572b4a0ed958814e90 Mon Sep 17 00:00:00 2001 From: anteprandium Date: Thu, 9 Mar 2017 20:38:33 +0100 Subject: [PATCH 08/15] Removed all splitting stuff and improved speed by a factor of 100 --- problema_1b.ipynb | 757 ++++++++++++++++++++++++---------------------- truncated.ipynb | 432 +++++++++++++------------- truncated.py | 129 ++++---- 3 files changed, 657 insertions(+), 661 deletions(-) diff --git a/problema_1b.ipynb b/problema_1b.ipynb index 2029ebf..c785235 100644 --- a/problema_1b.ipynb +++ b/problema_1b.ipynb @@ -1,388 +1,415 @@ { - "metadata": { - "name": "", - "signature": "sha256:0aaa10cffc9ae9f9651a957482fa8267e78dc329502acb33a9aafe48571a03b7" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ + "cells": [ { - "cells": [ - { - "cell_type": "code", - "collapsed": false, - "input": [ - "%run ipproblem" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 1 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "c=(4, 1, 1, 3, 4, 2, 2, 2, 2, 3, 1, 3)\n", - "A=[[1, 0, 0, 3, 1, 3, 3, 2, 1, 1, 3, 3],\n", - " [0, 3, 2, 0, 3, 2, 2, 2, 3, 0, 1, 2],\n", - " [0, 1, 2, 2, 1, 2, 0, 1, 2, 0, 3, 3],\n", - " [3, 0, 1, 2, 0, 0, 1, 1, 0, 1, 3, 1]]\n", - "b=(17, 2, 13, 9)\n", - "u=(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 2 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 2 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "set_verbose(0)\n", - "R=IPProblem(c,A,b,u)" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 3 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "G1=R.test_set_non_reducibles()" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 25 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "len(G1)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 26, - "text": [ - "82" - ] - } - ], - "prompt_number": 26 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "def check_set(R,G1):\n", - " for v in G1:\n", - " vp,vm=R.pm_split(v)\n", - " print (v,R.order(v, vector(ZZ,len(v)*[0]))>0, R.is_feasible(vp), R.is_feasible(vm))" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 27 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "G=R.minimal_test_set()" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 28 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "len(G)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 29, - "text": [ - "66" - ] - } - ], - "prompt_number": 29 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "#check_set(R,G)" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 9 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "H=R.inter_reduce(G1)\n", - "len(H)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 10, - "text": [ - "61" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "Z=R.inter_reduce(G)\n", - "len(Z)" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 11, - "text": [ - "66" - ] - } - ], - "prompt_number": 11 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "Z==G" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 12, - "text": [ - "True" - ] - } - ], - "prompt_number": 12 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "for v in H:\n", - " if not v in G:\n", - " print v\n", - " " - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 13 - }, + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%run ipproblem" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "c=(4, 1, 1, 3, 4, 2, 2, 2, 2, 3, 1, 3)\n", + "A=[[1, 0, 0, 3, 1, 3, 3, 2, 1, 1, 3, 3],\n", + " [0, 3, 2, 0, 3, 2, 2, 2, 3, 0, 1, 2],\n", + " [0, 1, 2, 2, 1, 2, 0, 1, 2, 0, 3, 3],\n", + " [3, 0, 1, 2, 0, 0, 1, 1, 0, 1, 3, 1]]\n", + "b=(17, 2, 13, 9)\n", + "u=(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "set_verbose(0)\n", + "R=IPProblem(c,A,b,u)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "G1=R.test_set_non_reducibles()" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": { + "collapsed": false + }, + "outputs": [ { - "cell_type": "code", - "collapsed": false, - "input": [ - "l=[]\n", - "for v in G:\n", - " if not v in H:\n", - " l.append(v)\n", - "print l" - ], - "language": "python", + "data": { + "text/plain": [ + "82" + ] + }, + "execution_count": 26, "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "[(1, 0, 0, -1, 0, 1, 0, 0, 0, -1, 0, 0), (1, 0, 0, -1, 0, 1, 0, 0, 0, 0, 0, -1), (0, 0, -1, -1, 0, 0, 0, 1, 0, 1, 0, 0), (1, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, -1), (0, 0, 0, -1, 0, -1, 0, 0, 0, 1, 0, 1)]\n" - ] - } - ], - "prompt_number": 14 - }, + "output_type": "execute_result" + } + ], + "source": [ + "len(G1)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def check_set(R,G1):\n", + " for v in G1:\n", + " vp,vm=R.pm_split(v)\n", + " print (v,R.order(v, vector(ZZ,len(v)*[0]))>0, R.is_feasible(vp), R.is_feasible(vm))" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "G=R.minimal_test_set()" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "collapsed": false + }, + "outputs": [ { - "cell_type": "code", - "collapsed": false, - "input": [ - "check_set(R,l)" - ], - "language": "python", + "data": { + "text/plain": [ + "66" + ] + }, + "execution_count": 29, "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "((1, 0, 0, -1, 0, 1, 0, 0, 0, -1, 0, 0), True, True, True)\n", - "((1, 0, 0, -1, 0, 1, 0, 0, 0, 0, 0, -1), True, True, True)\n", - "((0, 0, -1, -1, 0, 0, 0, 1, 0, 1, 0, 0), True, True, True)\n", - "((1, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, -1), True, True, True)\n", - "((0, 0, 0, -1, 0, -1, 0, 0, 0, 1, 0, 1), True, True, True)\n" - ] - } - ], - "prompt_number": 15 - }, + "output_type": "execute_result" + } + ], + "source": [ + "len(G)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "#check_set(R,G)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ { - "cell_type": "code", - "collapsed": false, - "input": [ - "R.get_feasible()" - ], - "language": "python", + "data": { + "text/plain": [ + "61" + ] + }, + "execution_count": 10, "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 16, - "text": [ - "(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)" - ] - } - ], - "prompt_number": 16 - }, + "output_type": "execute_result" + } + ], + "source": [ + "H=R.inter_reduce(G1)\n", + "len(H)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ { - "cell_type": "code", - "collapsed": false, - "input": [ - "v=R.minimal[0]" - ], - "language": "python", + "data": { + "text/plain": [ + "66" + ] + }, + "execution_count": 11, "metadata": {}, - "outputs": [], - "prompt_number": 17 - }, + "output_type": "execute_result" + } + ], + "source": [ + "Z=R.inter_reduce(G)\n", + "len(Z)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ { - "cell_type": "code", - "collapsed": false, - "input": [ - "R.walk_to_best(v, path=True)" - ], - "language": "python", + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 12, "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 18, - "text": [ - "[(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),\n", - " (1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0),\n", - " (1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0),\n", - " (1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1)]" - ] - } - ], - "prompt_number": 18 - }, + "output_type": "execute_result" + } + ], + "source": [ + "Z==G" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "for v in H:\n", + " if not v in G:\n", + " print v\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ { - "cell_type": "code", - "collapsed": false, - "input": [ - "[R.cost(v) for v in _]" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 19, - "text": [ - "[4, 7, 10, 13]" - ] - } - ], - "prompt_number": 19 - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "[(1, 0, 0, -1, 0, 1, 0, 0, 0, -1, 0, 0), (1, 0, 0, -1, 0, 1, 0, 0, 0, 0, 0, -1), (0, 0, -1, -1, 0, 0, 0, 1, 0, 1, 0, 0), (1, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, -1), (0, 0, 0, -1, 0, -1, 0, 0, 0, 1, 0, 1)]\n" + ] + } + ], + "source": [ + "l=[]\n", + "for v in G:\n", + " if not v in H:\n", + " l.append(v)\n", + "print l" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ { - "cell_type": "code", - "collapsed": false, - "input": [ - "set_verbose(1)\n", - "#R.test_set()" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 20 - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "((1, 0, 0, -1, 0, 1, 0, 0, 0, -1, 0, 0), True, True, True)\n", + "((1, 0, 0, -1, 0, 1, 0, 0, 0, 0, 0, -1), True, True, True)\n", + "((0, 0, -1, -1, 0, 0, 0, 1, 0, 1, 0, 0), True, True, True)\n", + "((1, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, -1), True, True, True)\n", + "((0, 0, 0, -1, 0, -1, 0, 0, 0, 1, 0, 1), True, True, True)\n" + ] + } + ], + "source": [ + "check_set(R,l)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ { - "cell_type": "code", - "collapsed": false, - "input": [ - "set_verbose(0)" - ], - "language": "python", + "data": { + "text/plain": [ + "(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)" + ] + }, + "execution_count": 16, "metadata": {}, - "outputs": [], - "prompt_number": 21 - }, + "output_type": "execute_result" + } + ], + "source": [ + "R.get_feasible()" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "v=R.minimal[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "collapsed": false + }, + "outputs": [ { - "cell_type": "code", - "collapsed": false, - "input": [], - "language": "python", + "data": { + "text/plain": [ + "[(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0),\n", + " (1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1)]" + ] + }, + "execution_count": 18, "metadata": {}, - "outputs": [], - "prompt_number": 21 - }, + "output_type": "execute_result" + } + ], + "source": [ + "R.walk_to_best(v, path=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ { - "cell_type": "code", - "collapsed": false, - "input": [], - "language": "python", + "data": { + "text/plain": [ + "[4, 7, 10, 13]" + ] + }, + "execution_count": 19, "metadata": {}, - "outputs": [] + "output_type": "execute_result" } ], - "metadata": {} + "source": [ + "[R.cost(v) for v in _]" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "set_verbose(1)\n", + "#R.test_set()" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "set_verbose(0)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.10" } - ] -} \ No newline at end of file + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/truncated.ipynb b/truncated.ipynb index 3e728ce..8d6ac30 100644 --- a/truncated.ipynb +++ b/truncated.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 222, + "execution_count": 62, "metadata": { "collapsed": false }, @@ -20,7 +20,7 @@ "\n", "xxx = random_lll(longitud, numero)\n", "yyy = random_lll(longitud, numero)\n", - "zzz = [vector(ZZ,z) for z in zzz]\n", + "zzz = [vector(ZZ,z) for z in xxx]\n", "ttt = [vector(ZZ,z) for z in yyy]\n", "\n", "#vvv = random_vvv(5000, 1000)\n", @@ -29,70 +29,7 @@ }, { "cell_type": "code", - "execution_count": 232, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1000 loops, best of 3: 1.37 ms per loop\n" - ] - } - ], - "source": [ - "%%timeit \n", - "for (e,v) in zip(zzz,ttt):\n", - " e*v" - ] - }, - { - "cell_type": "code", - "execution_count": 233, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "100 loops, best of 3: 10.3 ms per loop\n" - ] - } - ], - "source": [ - "%%timeit\n", - "for (e,v) in zip(xxx,yyy):\n", - " dotprod(e,v)" - ] - }, - { - "cell_type": "code", - "execution_count": 234, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "100 loops, best of 3: 10.5 ms per loop\n" - ] - } - ], - "source": [ - "%%timeit\n", - "for (e,v) in zip(zzz,ttt):\n", - " dotproduct(e,v)" - ] - }, - { - "cell_type": "code", - "execution_count": 231, + "execution_count": 168, "metadata": { "collapsed": false }, @@ -103,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 197, + "execution_count": 171, "metadata": { "collapsed": false, "scrolled": true @@ -113,28 +50,41 @@ "name": "stdout", "output_type": "stream", "text": [ - "3751 criterion 1, 0 criterion 2, 12603 reductions, 1593 non eligible, 459 equalities\n", + "146 criterion 1, 0 criterion 2, 1064 reductions, 48 non eligible, 22 equalities\n", " " ] } ], "source": [ "%%prun\n", - "vecs, g = bubu(A,b,c,u)\n" + "vecs, g = bubu(A1,b1,c1,u1)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 156, "metadata": { "collapsed": false }, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "81" + ] + }, + "execution_count": 156, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(vecs)" + ] }, { "cell_type": "code", - "execution_count": 198, + "execution_count": 157, "metadata": { "collapsed": false }, @@ -142,21 +92,101 @@ { "data": { "text/plain": [ - "169" + "[(1, 0, 0, 0, 0, 0, 0),\n", + " (0, 1, 0, 0, 0, 0, 0),\n", + " (0, 0, 1, 0, 0, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, 0),\n", + " (0, 0, 0, 0, 1, 0, 0),\n", + " (0, 0, 0, 0, 0, 1, 0),\n", + " (0, 0, 0, 0, 0, 0, 1),\n", + " (0, 0, 0, 0, 0, 1, -1),\n", + " (0, 0, 0, 0, 0, 1, -2),\n", + " (0, 0, 0, 0, -1, 1, -1),\n", + " (0, 0, 0, 0, -1, 0, 1),\n", + " (0, 0, 0, 0, -2, 0, 1),\n", + " (0, 0, 0, 1, 1, 0, -1),\n", + " (0, 0, 0, 1, 0, 0, -1),\n", + " (0, 0, 0, -1, -1, 0, 2),\n", + " (0, 0, 0, 1, -1, 0, -1),\n", + " (0, 0, 0, -1, 0, 0, 2),\n", + " (0, 0, 0, 1, -2, 0, -1),\n", + " (0, 0, 0, -1, 1, 1, 0),\n", + " (0, 0, 0, -1, 0, 1, 0),\n", + " (0, 0, 0, -1, -1, 1, 0),\n", + " (0, 0, 0, 1, -1, 0, 0),\n", + " (0, 0, 0, -2, 0, 1, 0),\n", + " (0, 0, 0, -1, 0, 1, -1),\n", + " (0, 0, 0, -3, 0, 1, 0),\n", + " (0, 0, 0, -4, 0, 1, 0),\n", + " (0, -1, 0, -2, 0, 1, 0),\n", + " (0, 1, 0, -2, 0, 0, 0),\n", + " (0, -2, 0, 0, 0, 1, 0),\n", + " (0, 1, 0, -1, 0, 0, 0),\n", + " (0, -2, 0, -1, 0, 1, 0),\n", + " (0, -3, 0, 0, 0, 1, 0),\n", + " (0, 2, 0, 0, 0, 0, -1),\n", + " (0, 4, 0, 0, 0, -1, 0),\n", + " (0, -2, 0, 0, 0, 1, -1),\n", + " (0, 1, 0, 0, 0, 0, -1),\n", + " (0, -1, 0, -1, 0, 1, 0),\n", + " (0, -3, 0, -1, 0, 1, 0),\n", + " (0, 3, 0, 0, -1, 0, 0),\n", + " (0, -1, 0, 0, -1, 1, 0),\n", + " (0, -2, 0, 0, -1, 1, 0),\n", + " (0, 1, 0, 0, -1, 0, 0),\n", + " (0, 1, 0, 0, -1, 0, -1),\n", + " (0, -1, 0, 0, 0, 1, 0),\n", + " (0, -1, 0, 4, 0, 0, 0),\n", + " (0, 2, 0, -1, -1, 0, -1),\n", + " (0, 1, 0, -1, 0, 0, -1),\n", + " (0, -1, 0, 3, 0, 0, 0),\n", + " (0, 2, 0, -3, -1, 0, 0),\n", + " (0, 2, 0, -2, -1, 0, 0),\n", + " (0, 1, 0, -1, -1, 0, 1),\n", + " (0, 1, 0, 0, 0, 0, -2),\n", + " (0, 1, 0, -1, -1, 0, 0),\n", + " (0, -1, 0, 0, 0, 1, -1),\n", + " (0, 0, -1, 0, 0, 1, -1),\n", + " (0, 1, -1, 0, 0, 0, 0),\n", + " (0, 0, -1, 1, 1, 0, 0),\n", + " (0, 0, 1, 0, -1, 0, -1),\n", + " (0, 0, -2, 0, 1, 1, 0),\n", + " (0, 0, -1, -1, 0, 1, 0),\n", + " (0, 0, 1, 0, 0, 0, -1),\n", + " (0, 0, -2, 0, 0, 1, 0),\n", + " (0, 0, -1, 1, 0, 0, 0),\n", + " (0, 0, 1, 0, -1, 0, 0),\n", + " (0, -1, -1, 0, 0, 1, 0),\n", + " (0, -1, -1, 4, 0, 0, 0),\n", + " (0, -1, -1, 3, 0, 0, 0),\n", + " (0, 1, 2, -3, 0, 0, 0),\n", + " (0, 0, 2, -1, 0, 0, 0),\n", + " (0, 0, -1, 1, -1, 0, 0),\n", + " (0, 1, -1, 0, -1, 0, 0),\n", + " (0, 1, -2, 0, 0, 0, 0),\n", + " (0, 1, -2, 0, -1, 0, 0),\n", + " (0, 0, -1, 0, -1, 1, 0),\n", + " (0, 0, -3, 0, 0, 1, 0),\n", + " (-1, 0, -1, 0, 0, 1, 0),\n", + " (1, 0, -2, 0, 0, 0, 0),\n", + " (-2, 0, 1, 0, 0, 1, 0),\n", + " (2, 0, -2, 0, -1, 0, 0),\n", + " (1, 0, 0, 0, -1, 0, 0),\n", + " (-2, 0, 0, 0, 0, 1, 0)]" ] }, - "execution_count": 198, + "execution_count": 157, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "len(vecs)" + "vecs" ] }, { "cell_type": "code", - "execution_count": 199, + "execution_count": 160, "metadata": { "collapsed": false }, @@ -236,104 +266,16 @@ "5 (0, 0, 2, -1, 0, 0, 0) True (20, -1, -7) True\n", "0 (0, 0, -1, 1, -1, 0, 0) True (-12, -6, 6) True\n", "8 (0, 1, -1, 0, -1, 0, 0) True (-13, -2, 3) True\n", - "3 (0, -1, 3, 0, 0, 0, 0) True (32, -5, -3) False\n", - "1 (0, -1, 2, 0, 0, 0, 1) True (24, 1, -1) True\n", - "4 (0, 1, -1, 0, -1, 0, -1) True (-16, -8, 0) True\n", - "2 (0, 1, -2, 0, -1, 0, 0) True (-24, -2, 2) True\n", "3 (0, 1, -2, 0, 0, 0, 0) True (-21, 5, 4) True\n", - "5 (0, 1, -1, 0, 0, 0, -1) True (-13, -1, 2) True\n", - "3 (0, 0, 1, -1, 0, 0, 1) True (12, 5, -5) True\n", - "35 (0, 0, -3, 0, 0, 1, 0) True (-28, 4, 0) True\n", + "2 (0, 1, -2, 0, -1, 0, 0) True (-24, -2, 2) True\n", "46 (0, 0, -1, 0, -1, 1, 0) True (-9, -3, 0) True\n", - "4 (0, 0, 1, 0, -2, 0, 0) True (5, -14, -3) True\n", - "9 (0, 1, 0, 0, -2, 0, -1) True (-8, -15, -1) True\n", - "1 (0, 1, -2, 0, -2, 0, 0) True (-27, -9, 0) True\n", - "12 (0, 1, 0, 0, -3, 0, 0) True (-8, -16, 0) True\n", - "7 (0, 1, -1, 0, -2, 0, 0) True (-16, -9, 1) True\n", - "13 (0, 1, 0, 0, -2, 0, 0) True (-5, -9, 2) True\n", - "51 (0, 0, 0, 0, -2, 1, 0) True (-1, -10, -1) True\n", - "47 (0, 0, -1, 0, 0, 1, 0) True (-6, 4, 2) True\n", - "2 (0, 0, -1, 0, 0, 0, 2) True (-5, 12, 5) True\n", - "0 (0, 0, -1, 0, 2, 0, 1) True (-2, 20, 6) True\n", - "3 (0, 0, 1, 0, -3, 0, 0) True (2, -21, -5) True\n", - "0 (0, 0, 0, -1, 3, 0, 1) True (10, 26, 0) True\n", - "5 (0, 0, 1, 1, -4, 0, -1) True (-2, -33, -1) True\n", - "8 (0, 0, 1, 1, -5, 0, 0) True (-2, -34, 0) True\n", - "5 (0, 0, 0, 1, -2, 0, 0) True (-4, -13, 5) True\n", - "3 (0, 0, 0, 1, -4, 0, 0) True (-10, -27, 1) True\n", - "2 (0, 0, 1, 1, -3, 0, -2) True (-2, -32, -2) True\n", - "2 (0, 0, 1, 0, -4, 0, 0) True (-1, -28, -7) True\n", - "1 (0, 0, 1, 1, 0, 0, -3) True (4, -17, 1) True\n", - "0 (0, 0, -1, -1, 1, 0, 3) True (-1, 24, 1) True\n", - "0 (0, 0, -1, -2, 0, 0, 5) True (0, 28, -4) False\n", - "3 (0, 0, -1, -1, 0, 0, 4) True (-1, 23, 2) True\n", - "3 (0, 0, 1, 1, -2, 0, -2) True (1, -25, 0) True\n", - "33 (0, 0, -1, -2, 0, 1, 0) True (-10, 2, -16) True\n", - "23 (-1, 0, 0, -1, 0, 1, 0) True (0, -1, -11) True\n", - "10 (1, 0, -1, -1, 0, 0, 0) True (-10, 3, -5) True\n", - "13 (-2, 0, 1, 0, 0, 1, 0) True (10, -4, -6) True\n", - "16 (1, 0, 0, -1, 0, 0, 0) True (1, 3, -4) True\n", - "7 (-2, 0, 0, 0, 0, 1, 0) True (-1, -4, -7) True\n", - "44 (2, 0, 0, 0, -2, 0, 0) True (0, -6, 6) True\n", - "22 (1, 0, 0, 0, -1, 0, 0) True (0, -3, 3) True\n", - "19 (1, 0, 1, 1, -1, 0, -4) True (1, -26, 1) True\n", - "18 (1, 0, 0, 0, -1, 0, -1) True (-3, -9, 0) True\n", - "15 (1, 0, 0, 0, 0, 0, -2) True (-3, -8, -1) True\n", - "4 (0, 0, 1, 1, -1, 0, -2) True (4, -18, 2) True\n", - "25 (-1, 0, -1, 0, 1, 1, 0) True (-6, 7, -1) True\n", - "28 (-1, 0, -1, 0, 0, 1, 1) True (-6, 6, 0) True\n", - "21 (1, 0, -1, 0, 0, 0, 1) True (-5, 10, 7) True\n", - "63 (3, 0, -1, 0, 0, 0, 0) True (-2, 12, 14) True\n", - "42 (2, 0, 0, 0, 0, 0, -1) True (3, 2, 7) True\n", - "19 (1, 0, 0, 0, 0, 0, -1) True (0, -2, 2) True\n", - "20 (1, 0, 0, 0, -3, 0, 0) True (-6, -17, -1) True\n", - "20 (1, 0, -1, 0, 3, 0, 0) True (1, 25, 10) True\n", - "21 (1, 0, 0, 0, -2, 0, 0) True (-3, -10, 1) True\n", - "42 (2, 0, -1, 0, 2, 0, 0) True (1, 22, 13) True\n", - "30 (-1, 0, 0, 0, 0, 1, 0) True (2, 0, -2) True\n", - "41 (2, 0, -1, 0, 1, 0, 0) True (-2, 15, 11) True\n", - "18 (1, 0, -1, 0, 1, 0, 0) True (-5, 11, 6) True\n", - "17 (1, 0, -1, 0, 0, 0, 0) True (-8, 4, 4) True\n", - "15 (1, 0, -1, 0, -2, 0, 0) True (-14, -10, 0) True\n", - "2 (0, 0, -1, -1, -1, 0, 4) True (-4, 16, 0) True\n", - "19 (1, 0, 0, -1, -1, 0, 1) True (1, 2, -3) True\n", - "38 (2, 0, 0, -1, -1, 0, 0) True (1, 0, -1) True\n", - "15 (1, 0, 0, -1, -1, 0, 0) True (-2, -4, -6) True\n", + "35 (0, 0, -3, 0, 0, 1, 0) True (-28, 4, 0) True\n", "24 (-1, 0, -1, 0, 0, 1, 0) True (-9, 0, -3) True\n", - "29 (-1, 0, 0, 0, -1, 1, 0) True (-1, -7, -4) True\n", - "26 (-1, 0, 0, 0, 0, 1, -1) True (-1, -6, -5) True\n", - "13 (1, 0, -1, 0, 0, 0, -1) True (-11, -2, 1) True\n", - "5 (0, 0, 1, 1, 0, 0, -2) True (7, -11, 4) True\n", - "3 (1, -1, -1, 0, 1, 0, 0) True (-6, 6, 0) True\n", - "4 (1, -1, 0, 0, 0, 0, -1) True (-1, -7, -4) True\n", - "2 (1, -1, -1, 0, 0, 0, 0) True (-9, -1, -2) True\n", - "4 (0, 0, 0, 1, -3, 0, 0) True (-7, -20, 3) True\n", - "2 (0, 0, 1, -1, 3, 0, 0) True (18, 20, -2) True\n", - "10 (1, 0, -2, 0, -1, 0, 0) True (-22, -3, 1) True\n", - "16 (1, 0, -1, 0, -1, 0, 0) True (-11, -3, 2) True\n", - "9 (1, -1, 0, 0, 1, 0, 0) True (5, 6, 1) True\n", - "8 (1, -1, 0, 0, 0, 0, 0) True (2, -1, -1) True\n", - "7 (1, 0, -2, 0, 0, 0, -1) True (-22, -2, 0) True\n", - "4 (1, 0, -3, 0, -1, 0, 0) True (-33, -3, 0) True\n", "11 (1, 0, -2, 0, 0, 0, 0) True (-19, 4, 3) True\n", - "5 (1, 0, -3, 0, 0, 0, 0) True (-30, 4, 2) True\n", - "1 (-1, 0, 4, 0, 0, 0, 0) True (41, -4, -1) False\n", - "9 (1, 0, 0, -2, 0, 0, 0) True (-1, 2, -13) True\n", - "12 (1, 0, 0, -1, 0, 0, -1) True (-2, -3, -7) True\n", - "8 (1, 0, 1, -3, 0, 0, 0) True (8, 1, -21) True\n", - "2 (1, 0, 0, -3, 0, 0, 0) True (-3, 1, -22) True\n", - "1 (1, -1, 0, -1, 0, 0, 0) True (0, -2, -10) True\n", - "1 (1, 0, 1, -4, 0, 0, 0) True (6, 0, -30) True\n", - "5 (-1, 0, 0, 4, 0, 0, 0) True (5, 0, 31) True\n", - "4 (-2, 0, -1, 8, 0, 0, 0) True (-1, 0, 61) False\n", - "0 (-1, -2, 0, 0, 0, 1, 0) True (0, -10, -14) True\n", - "7 (-1, 2, 0, 0, 0, 0, 0) True (-1, 6, 7) True\n", - "7 (1, -1, 0, 0, -1, 0, 0) True (-1, -8, -3) True\n", - "15 (-1, -1, 0, 0, 0, 1, 0) True (1, -5, -8) True\n", - "1 (0, 0, 1, -1, 2, 0, 0) True (15, 13, -4) True\n", - "2 (0, 0, 0, 1, -5, 0, 0) True (-13, -34, -1) True\n", - "52 (0, 0, 0, 0, -1, 1, 0) True (2, -3, 1) True\n", - "6 (0, 0, 1, 1, -3, 0, -1) True (1, -26, 1) True\n" + "13 (-2, 0, 1, 0, 0, 1, 0) True (10, -4, -6) True\n", + "33 (2, 0, -2, 0, -1, 0, 0) True (-19, 1, 6) True\n", + "22 (1, 0, 0, 0, -1, 0, 0) True (0, -3, 3) True\n", + "7 (-2, 0, 0, 0, 0, 1, 0) True (-1, -4, -7) True\n" ] } ], @@ -343,26 +285,7 @@ }, { "cell_type": "code", - "execution_count": 26, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, False, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, False, False, True, True, False, False, True, True, False, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, False, False, True, True, True, True, True, True, True, True, True, False, True, True, True, False, True, True, True, True]\n" - ] - } - ], - "source": [ - "print g.eligible" - ] - }, - { - "cell_type": "code", - "execution_count": 246, + "execution_count": 161, "metadata": { "collapsed": false }, @@ -373,7 +296,7 @@ }, { "cell_type": "code", - "execution_count": 250, + "execution_count": 162, "metadata": { "collapsed": false }, @@ -382,13 +305,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "787 criterion 1, 0 criterion 2, 1952 reductions, 974 non eligible, 52 equalities\n", - " " + "787 criterion 1, 0 criterion 2, 1952 reductions, 974 non eligible, 52 equalities\n" ] } ], "source": [ - "%%prun\n", + "#%%prun\n", "\n", "A = matrix(ZZ, [[3,1,11,2,3,5,3], [4, 5, 0, 1, 7,4, 6], [5,6,1,9,2,3,3]])\n", "c = vector(ZZ, [23,15,6,7,1,53,4])\n", @@ -399,7 +321,7 @@ }, { "cell_type": "code", - "execution_count": 248, + "execution_count": 163, "metadata": { "collapsed": false }, @@ -410,7 +332,7 @@ "77" ] }, - "execution_count": 248, + "execution_count": 163, "metadata": {}, "output_type": "execute_result" } @@ -421,40 +343,100 @@ }, { "cell_type": "code", - "execution_count": 249, + "execution_count": 165, "metadata": { "collapsed": false }, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "[(1, 0, 0, 0, 0, 0, 0), (0, 1, 0, 0, 0, 0, 0), (0, 0, 1, 0, 0, 0, 0), (0, 0, 0, 1, 0, 0, 0), (0, 0, 0, 0, 1, 0, 0), (0, 0, 0, 0, 0, 1, 0), (0, 0, 0, 0, 0, 0, 1), (0, 0, 0, 0, 0, 1, -1), (0, 0, 0, 0, -1, 1, -1), (0, 0, 0, -1, 0, 1, -1), (0, 0, 0, 1, -1, 0, 0), (0, 0, 0, 1, -1, 0, -1), (0, 0, 0, -1, 0, 1, 0), (0, 0, 0, 1, 0, 0, -1), (0, 0, 0, 0, -1, 0, 1), (0, 0, 1, 0, 1, 0, -1), (0, 0, -1, 1, -1, 0, 0), (0, 0, 1, -1, 0, 0, 1), (0, 0, -1, 0, 0, 1, -1), (0, 0, -1, -1, 0, 1, 0), (0, 0, 1, 0, -1, 0, 0), (0, 0, 1, 0, 0, 0, -1), (0, 0, -1, 1, 0, 0, 0), (0, 0, 1, 0, -1, 0, -1), (0, 0, -1, 0, 0, 1, 0), (0, 0, -1, 0, -1, 1, 0), (0, 0, 0, -1, -1, 1, 0), (0, -1, -1, 0, 0, 1, 0), (0, 1, 1, -1, -1, 0, 0), (0, 1, 0, -1, 0, 0, 1), (0, 1, 1, -1, 0, 0, 0), (0, 1, 0, -1, 1, 0, 0), (0, 1, 0, -1, 0, 0, 0), (0, -1, 0, 0, -1, 1, 0), (0, 1, -1, 0, 0, 0, 0), (0, -1, 0, -1, 0, 1, 0), (0, 1, 0, 0, -1, 0, 0), (0, 1, -1, 0, 0, 0, -1), (0, -1, 0, 0, 0, 1, 1), (0, 1, 0, -1, 0, 0, -1), (0, 1, 0, -1, -1, 0, 0), (0, -1, 0, 0, 0, 1, 0), (0, 1, -1, 0, -1, 0, 0), (0, 1, -1, 0, -1, 0, -1), (1, -1, 0, 0, 1, 0, 0), (-1, 0, 0, 0, -1, 1, 0), (-1, 0, 0, 0, 0, 1, 0), (1, -1, 0, 0, 0, 0, 0), (-1, 0, 0, -1, 0, 1, 0), (1, 0, -1, 0, 0, 0, -1), (1, -1, -1, 0, 1, 0, 0), (0, 1, 0, 0, -1, 0, -1), (1, 0, 0, 0, 0, 0, -1), (0, 1, 0, 0, 0, 0, -1), (1, -1, -1, 0, 0, 0, 0), (1, -1, 0, -1, 0, 0, 0), (-1, 0, -1, 1, 0, 1, 0), (1, 0, 0, -1, 0, 0, -1), (1, -1, 0, 0, 0, 0, -1), (-1, 0, -1, 0, 0, 1, 1), (1, 0, 0, 0, -1, 0, 0), (-1, -1, 0, 0, 0, 1, 0), (1, 0, 0, -1, 0, 0, 0), (1, -1, 0, 0, -1, 0, 0), (-1, 0, -1, 0, 1, 1, 0), (1, 0, 0, 0, -1, 0, -1), (1, 0, -1, 0, 0, 0, 0), (-1, 0, 0, 0, 0, 1, -1), (1, 0, 0, -1, -1, 0, 1), (1, 0, 0, -1, -1, 0, 0), (1, 0, -1, -1, 0, 0, 1), (1, 0, -1, -1, 1, 0, 0), (1, 0, -1, -1, 0, 0, 0), (-1, 0, -1, 0, 0, 1, 0), (1, 0, -1, 0, -1, 0, 0), (0, -1, 0, 0, 0, 1, -1), (0, 0, 0, 0, -1, 1, 0)]\n" - ] - } - ], - "source": [ - "print g.vectors" - ] - }, - { - "cell_type": "code", - "execution_count": 238, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[True, True, True, True, True, True, True, True, False, True, True, True, True, True, True, True, False, False, False, True, True, False, True, True, False, True, False, False, True, True, False, True, True, False, False, False, False, False, False, True, False, False, False, False, True, False, False, True, True, False, False, False, False, False, False, False, True, True, True, False, True, True, True, False, False, True, False, True, False, False, False, True, True, False, False, True, True, True, True, True, True, True, True, False, False, True, True, True, False, True, True, True, True, True, True, True, False, True, True, True, True, False, False, True, True, False, False, True, True, True, True, True, False, True, False, False, True, False, False, False, False, False, True, False, True, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, True, False, False, False, False]\n" - ] + "data": { + "text/plain": [ + "[(1, 0, 0, 0, 0, 0, 0),\n", + " (0, 1, 0, 0, 0, 0, 0),\n", + " (0, 0, 1, 0, 0, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, 0),\n", + " (0, 0, 0, 0, 1, 0, 0),\n", + " (0, 0, 0, 0, 0, 1, 0),\n", + " (0, 0, 0, 0, 0, 0, 1),\n", + " (0, 0, 0, 0, 0, 1, -1),\n", + " (0, 0, 0, 0, -1, 1, -1),\n", + " (0, 0, 0, -1, 0, 1, -1),\n", + " (0, 0, 0, 1, -1, 0, 0),\n", + " (0, 0, 0, 1, -1, 0, -1),\n", + " (0, 0, 0, -1, 0, 1, 0),\n", + " (0, 0, 0, 1, 0, 0, -1),\n", + " (0, 0, 0, 0, -1, 0, 1),\n", + " (0, 0, 1, 0, 1, 0, -1),\n", + " (0, 0, -1, 1, -1, 0, 0),\n", + " (0, 0, 1, -1, 0, 0, 1),\n", + " (0, 0, -1, 0, 0, 1, -1),\n", + " (0, 0, -1, -1, 0, 1, 0),\n", + " (0, 0, 1, 0, -1, 0, 0),\n", + " (0, 0, 1, 0, 0, 0, -1),\n", + " (0, 0, -1, 1, 0, 0, 0),\n", + " (0, 0, 1, 0, -1, 0, -1),\n", + " (0, 0, -1, 0, 0, 1, 0),\n", + " (0, 0, -1, 0, -1, 1, 0),\n", + " (0, 0, 0, -1, -1, 1, 0),\n", + " (0, -1, -1, 0, 0, 1, 0),\n", + " (0, 1, 1, -1, -1, 0, 0),\n", + " (0, 1, 0, -1, 0, 0, 1),\n", + " (0, 1, 1, -1, 0, 0, 0),\n", + " (0, 1, 0, -1, 1, 0, 0),\n", + " (0, 1, 0, -1, 0, 0, 0),\n", + " (0, -1, 0, 0, -1, 1, 0),\n", + " (0, 1, -1, 0, 0, 0, 0),\n", + " (0, -1, 0, -1, 0, 1, 0),\n", + " (0, 1, 0, 0, -1, 0, 0),\n", + " (0, 1, -1, 0, 0, 0, -1),\n", + " (0, -1, 0, 0, 0, 1, 1),\n", + " (0, 1, 0, -1, 0, 0, -1),\n", + " (0, 1, 0, -1, -1, 0, 0),\n", + " (0, -1, 0, 0, 0, 1, 0),\n", + " (0, 1, -1, 0, -1, 0, 0),\n", + " (0, 1, -1, 0, -1, 0, -1),\n", + " (1, -1, 0, 0, 1, 0, 0),\n", + " (-1, 0, 0, 0, -1, 1, 0),\n", + " (-1, 0, 0, 0, 0, 1, 0),\n", + " (1, -1, 0, 0, 0, 0, 0),\n", + " (-1, 0, 0, -1, 0, 1, 0),\n", + " (1, 0, -1, 0, 0, 0, -1),\n", + " (1, -1, -1, 0, 1, 0, 0),\n", + " (0, 1, 0, 0, -1, 0, -1),\n", + " (1, 0, 0, 0, 0, 0, -1),\n", + " (0, 1, 0, 0, 0, 0, -1),\n", + " (1, -1, -1, 0, 0, 0, 0),\n", + " (1, -1, 0, -1, 0, 0, 0),\n", + " (-1, 0, -1, 1, 0, 1, 0),\n", + " (1, 0, 0, -1, 0, 0, -1),\n", + " (1, -1, 0, 0, 0, 0, -1),\n", + " (-1, 0, -1, 0, 0, 1, 1),\n", + " (1, 0, 0, 0, -1, 0, 0),\n", + " (-1, -1, 0, 0, 0, 1, 0),\n", + " (1, 0, 0, -1, 0, 0, 0),\n", + " (1, -1, 0, 0, -1, 0, 0),\n", + " (-1, 0, -1, 0, 1, 1, 0),\n", + " (1, 0, 0, 0, -1, 0, -1),\n", + " (1, 0, -1, 0, 0, 0, 0),\n", + " (-1, 0, 0, 0, 0, 1, -1),\n", + " (1, 0, 0, -1, -1, 0, 1),\n", + " (1, 0, 0, -1, -1, 0, 0),\n", + " (1, 0, -1, -1, 0, 0, 1),\n", + " (1, 0, -1, -1, 1, 0, 0),\n", + " (1, 0, -1, -1, 0, 0, 0),\n", + " (-1, 0, -1, 0, 0, 1, 0),\n", + " (1, 0, -1, 0, -1, 0, 0),\n", + " (0, -1, 0, 0, 0, 1, -1),\n", + " (0, 0, 0, 0, -1, 1, 0)]" + ] + }, + "execution_count": 165, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "print g.eligible" + "vects" ] }, { @@ -478,7 +460,7 @@ ], "metadata": { "kernelspec": { - "display_name": "SageMath 7.5.1", + "display_name": "SageMath 7.1", "language": "", "name": "sagemath" }, @@ -492,7 +474,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.13" + "version": "2.7.10" } }, "nbformat": 4, diff --git a/truncated.py b/truncated.py index 20feb63..da82c4a 100755 --- a/truncated.py +++ b/truncated.py @@ -24,40 +24,40 @@ def let(a,b): if a[i]>b[i]: return False return True - - + +def let_pp(a,b): + "True if and only if a^+ is less or equal than b^+." + for i in xrange(len(a)): + if a[i]>0 and a[i]>max(b[i], 0): + return False + return True + +def let_pm(a,b): + "True if and only if a^+ is less or equal than b^-." + for i in xrange(len(a)): + if a[i]>0 and a[i]>max(-b[i], 0): + return False + return True + +def let_mp(a,b): + "True if and only if a^- is less or equal than b^+." + for i in xrange(len(a)): + if a[i]<0 and -a[i]>max(b[i], 0): + return False + return True + +def let_mm(a,b): + "True if and only if a^- is less or equal than b^-." + for i in xrange(len(a)): + if a[i]<0 and -a[i]>max(-b[i], 0): + return False + return True + def standard_basis(n): return identity_matrix(ZZ,n).rows() - -# def pm_split3(v): -# "Split a vector `v` into its positive and negative part, so that $v=v^-v^-$." -# up = [] -# um = [] -# for a in v: -# if a>=0: -# up.append(a) -# um.append(0) -# else: -# up.append(0) -# um.append(-a) -# return vector(ZZ,up), vector(ZZ,um) -# -# -# def pm_split2(v): -# """ slightly faster than pm_split3""" -# l = len(v) -# up = [0]*l -# um = [0]*l -# for i in xrange(l): -# if v[i]>0: -# up[i]=v[i] -# else: -# um[i]=-v[i] -# return vector(ZZ,up), vector(ZZ,um) -# def pm_split(v): """ slightly faster than pm_split2""" l = len(v) @@ -82,13 +82,9 @@ def __init__(self, A, c, b, u): self.u = u self.vectors = [] self.cv = [] - self.vecp = [] - self.vecn = [] + self.Av = [] self.pairs = [] self.psupp = [] - self.Avp = [] - self.Avm = [] - self.eligible = [] for e in identity_matrix(ZZ,self.n).rows(): self.add_element(e) @@ -101,18 +97,12 @@ def add_element(self, v, check=True): e = v if cv>0 else -v # this makes sure that e^+ >_c e^-. l = len(self.vectors) self.vectors.append(e) + self.cv.append(abs(cv)) + self.Av.append(A*e) + self.psupp.append(set(e.support())) if l: # true if this is not the first vector for i in xrange(l): self.pairs.append((i,l)) - ep, em = pm_split(e) - self.vecp.append(ep) - self.vecn.append(em) - self.psupp.append(set(e.support())) - Avp, Avm = pm_split(A*e) - self.Avp.append(Avp) - self.Avm.append(Avm) - self.cv.append(abs(cv)) - self.eligible.append(let(ep,self.u) and let(em,self.u) and let(A*ep,self.b) and let(A*em,self.b) ) def criterion_1(self, i, j): @@ -159,24 +149,21 @@ def reduce_by_ith(self, s, i): """ round = 0 v = self.vectors[i] - vp = self.vecp[i] - vm = self.vecn[i] - Avp = self.Avp[i] - Avm = self.Avm[i] + Av = self.Av[i] w = s # if w == v or w == -v: return vector(ZZ,self.n*[0]) - while True and not isz(w): - wp, wm = pm_split(w) - Awp, Awm = pm_split(A*w) - if let(vp, wp) and let(vm,wm) and let(Avp, Awp): + while not isz(w): + Aw = A*w + if let_pp(v,w) and let_mm(v,w) and let_pp(Av, Aw): # w is reducible round += 1 w = w-v - elif let(vp,wm) and let(vm,wp) and let(Avp,Awm): + elif let_pm(v,w) and let_mp(v,w) and let_pm(Av, Aw): # -w is reducible + # print "-", w, -w-v round += 1 w = -w-v else: @@ -191,24 +178,22 @@ def reduce_by_ith(self, s, i): def reduce(self, v): """reduce""" - # for i in range(len(self.vectors)): - # r = self.reduce_by_ith(v, i) - # if not (r is False): - # return r - # return False + # print "r->:", v l = len(self.vectors) - vectors = deque(range(l)) + indices = deque(range(l)) i = 0 w = v while i200: break + if len(g.vectors)>100: break i, j = g.pop() if g.criterion_1(i,j): c1 += 1 @@ -262,13 +247,15 @@ def bubu(A,b,c,u): # 2.2.1 #if g.eligible[i]: r = g.vectors[j]-g.vectors[i] - rp,rm = pm_split(r) - if let(rp,u) and let(rm,u) and let(A*rp,b) and let(A*rm,b) : + Ar = A*r + # rp,rm = pm_split(r) + if let_pp(r,u) and let_mp(r,u) and let_pp(Ar,b) and let_mp(Ar,b) : rx +=1 - # r = g.vectors[j]-g.vectors[i] c = g.reduce(r) if not isz(c): g.add_element(c) + # print "+", c + # print g.vectors else: elig += 1 next @@ -279,8 +266,8 @@ def bubu(A,b,c,u): -A = matrix(ZZ, [[3,1,11,2,3,5,3], [4, 5, 0, 1, 7,4, 6], [5,6,1,9,2,3,3]]) -c = vector(ZZ, [23,15,6,7,1,53,4]) -b = vector(ZZ, [31,27,38]) -u = vector(ZZ, 7*[38]) +A1 = matrix(ZZ, [[3,1,11,2,3,5,3], [4, 5, 0, 1, 7,4, 6], [5,6,1,9,2,3,3]]) +c1 = vector(ZZ, [23,15,6,7,1,53,4]) +b1 = vector(ZZ, [31,27,38]) +u1 = vector(ZZ, 7*[38]) \ No newline at end of file From ee4c84309deeffb0219a83e4b1b5aadbad29405a Mon Sep 17 00:00:00 2001 From: anteprandium Date: Tue, 28 Mar 2017 11:21:46 +0200 Subject: [PATCH 09/15] Fix to criterion 2; added self_reduce and changed back eligibility criterion --- truncated.ipynb | 974 ++++++++++++++++++++++++++++++++++-------------- truncated.py | 328 +++++++++++----- 2 files changed, 930 insertions(+), 372 deletions(-) diff --git a/truncated.ipynb b/truncated.ipynb index 8d6ac30..3b71f6e 100644 --- a/truncated.ipynb +++ b/truncated.ipynb @@ -2,18 +2,17 @@ "cells": [ { "cell_type": "code", - "execution_count": 62, + "execution_count": 297, "metadata": { "collapsed": false }, "outputs": [], "source": [ - "\n", "def random_vvv(l,n):\n", - " return [vector(ZZ,[ZZ.random_element() for i in xrange(l)] ) for j in xrange(n)]\n", + " return [vector(ZZ,[ZZ.random_element() for i in xrange(l)]) for j in xrange(n)]\n", "\n", "def random_lll(l,n):\n", - " return [ [ZZ.random_element() for i in xrange(l)] for j in xrange(n)]\n", + " return [ [ZZ.random_element() for i in xrange(l)] for j in xrange(n)]\n", "\n", "longitud = 500\n", "numero = 100\n", @@ -29,18 +28,47 @@ }, { "cell_type": "code", - "execution_count": 168, + "execution_count": 401, "metadata": { "collapsed": false }, "outputs": [], "source": [ + "reset()\n", "load(\"truncated.py\")" ] }, { "cell_type": "code", - "execution_count": 171, + "execution_count": 402, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(\n", + "[ 3 1 11 2 3 5 3] \n", + "[ 4 5 0 1 7 4 6] \n", + "[ 5 6 1 9 2 3 3], (31, 27, 38), (23, 15, 6, 7, 1, 53, 4),\n", + "\n", + "(38, 38, 38, 38, 38, 38, 38)\n", + ")" + ] + }, + "execution_count": 402, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A1, b1, c1, u1" + ] + }, + { + "cell_type": "code", + "execution_count": 403, "metadata": { "collapsed": false, "scrolled": true @@ -50,19 +78,17 @@ "name": "stdout", "output_type": "stream", "text": [ - "146 criterion 1, 0 criterion 2, 1064 reductions, 48 non eligible, 22 equalities\n", - " " + "3496 criterion 1, 689 criterion 2, 5774 criterion 3, 83 non eligible, 14 equalities, 384 reductions, of which 246 to zero\n" ] } ], "source": [ - "%%prun\n", - "vecs, g = bubu(A1,b1,c1,u1)\n" + "vecs, g = bubu(A1,b1,c1,vector(ZZ, 7*[1]))\n" ] }, { "cell_type": "code", - "execution_count": 156, + "execution_count": 404, "metadata": { "collapsed": false }, @@ -70,10 +96,10 @@ { "data": { "text/plain": [ - "81" + "145" ] }, - "execution_count": 156, + "execution_count": 404, "metadata": {}, "output_type": "execute_result" } @@ -84,7 +110,18 @@ }, { "cell_type": "code", - "execution_count": 157, + "execution_count": 405, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "g.self_reduce()" + ] + }, + { + "cell_type": "code", + "execution_count": 406, "metadata": { "collapsed": false }, @@ -92,101 +129,184 @@ { "data": { "text/plain": [ - "[(1, 0, 0, 0, 0, 0, 0),\n", - " (0, 1, 0, 0, 0, 0, 0),\n", - " (0, 0, 1, 0, 0, 0, 0),\n", - " (0, 0, 0, 1, 0, 0, 0),\n", - " (0, 0, 0, 0, 1, 0, 0),\n", - " (0, 0, 0, 0, 0, 1, 0),\n", - " (0, 0, 0, 0, 0, 0, 1),\n", - " (0, 0, 0, 0, 0, 1, -1),\n", - " (0, 0, 0, 0, 0, 1, -2),\n", - " (0, 0, 0, 0, -1, 1, -1),\n", - " (0, 0, 0, 0, -1, 0, 1),\n", - " (0, 0, 0, 0, -2, 0, 1),\n", - " (0, 0, 0, 1, 1, 0, -1),\n", - " (0, 0, 0, 1, 0, 0, -1),\n", - " (0, 0, 0, -1, -1, 0, 2),\n", - " (0, 0, 0, 1, -1, 0, -1),\n", - " (0, 0, 0, -1, 0, 0, 2),\n", - " (0, 0, 0, 1, -2, 0, -1),\n", - " (0, 0, 0, -1, 1, 1, 0),\n", - " (0, 0, 0, -1, 0, 1, 0),\n", - " (0, 0, 0, -1, -1, 1, 0),\n", - " (0, 0, 0, 1, -1, 0, 0),\n", - " (0, 0, 0, -2, 0, 1, 0),\n", - " (0, 0, 0, -1, 0, 1, -1),\n", - " (0, 0, 0, -3, 0, 1, 0),\n", - " (0, 0, 0, -4, 0, 1, 0),\n", - " (0, -1, 0, -2, 0, 1, 0),\n", - " (0, 1, 0, -2, 0, 0, 0),\n", - " (0, -2, 0, 0, 0, 1, 0),\n", - " (0, 1, 0, -1, 0, 0, 0),\n", - " (0, -2, 0, -1, 0, 1, 0),\n", - " (0, -3, 0, 0, 0, 1, 0),\n", - " (0, 2, 0, 0, 0, 0, -1),\n", - " (0, 4, 0, 0, 0, -1, 0),\n", - " (0, -2, 0, 0, 0, 1, -1),\n", - " (0, 1, 0, 0, 0, 0, -1),\n", - " (0, -1, 0, -1, 0, 1, 0),\n", - " (0, -3, 0, -1, 0, 1, 0),\n", - " (0, 3, 0, 0, -1, 0, 0),\n", - " (0, -1, 0, 0, -1, 1, 0),\n", - " (0, -2, 0, 0, -1, 1, 0),\n", - " (0, 1, 0, 0, -1, 0, 0),\n", - " (0, 1, 0, 0, -1, 0, -1),\n", - " (0, -1, 0, 0, 0, 1, 0),\n", - " (0, -1, 0, 4, 0, 0, 0),\n", - " (0, 2, 0, -1, -1, 0, -1),\n", - " (0, 1, 0, -1, 0, 0, -1),\n", - " (0, -1, 0, 3, 0, 0, 0),\n", - " (0, 2, 0, -3, -1, 0, 0),\n", - " (0, 2, 0, -2, -1, 0, 0),\n", - " (0, 1, 0, -1, -1, 0, 1),\n", - " (0, 1, 0, 0, 0, 0, -2),\n", - " (0, 1, 0, -1, -1, 0, 0),\n", - " (0, -1, 0, 0, 0, 1, -1),\n", - " (0, 0, -1, 0, 0, 1, -1),\n", - " (0, 1, -1, 0, 0, 0, 0),\n", - " (0, 0, -1, 1, 1, 0, 0),\n", - " (0, 0, 1, 0, -1, 0, -1),\n", - " (0, 0, -2, 0, 1, 1, 0),\n", - " (0, 0, -1, -1, 0, 1, 0),\n", - " (0, 0, 1, 0, 0, 0, -1),\n", - " (0, 0, -2, 0, 0, 1, 0),\n", - " (0, 0, -1, 1, 0, 0, 0),\n", - " (0, 0, 1, 0, -1, 0, 0),\n", - " (0, -1, -1, 0, 0, 1, 0),\n", - " (0, -1, -1, 4, 0, 0, 0),\n", - " (0, -1, -1, 3, 0, 0, 0),\n", - " (0, 1, 2, -3, 0, 0, 0),\n", - " (0, 0, 2, -1, 0, 0, 0),\n", - " (0, 0, -1, 1, -1, 0, 0),\n", - " (0, 1, -1, 0, -1, 0, 0),\n", - " (0, 1, -2, 0, 0, 0, 0),\n", - " (0, 1, -2, 0, -1, 0, 0),\n", - " (0, 0, -1, 0, -1, 1, 0),\n", - " (0, 0, -3, 0, 0, 1, 0),\n", - " (-1, 0, -1, 0, 0, 1, 0),\n", - " (1, 0, -2, 0, 0, 0, 0),\n", - " (-2, 0, 1, 0, 0, 1, 0),\n", - " (2, 0, -2, 0, -1, 0, 0),\n", - " (1, 0, 0, 0, -1, 0, 0),\n", - " (-2, 0, 0, 0, 0, 1, 0)]" + "114" ] }, - "execution_count": 157, + "execution_count": 406, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "vecs" + "len(g.vectors)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Re-test" + ] + }, + { + "cell_type": "code", + "execution_count": 407, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "133 criterion 1, 10 criterion 2, 99 criterion 3, 0 non eligible, 0 equalities, 34 reductions, of which 15 to zero\n" + ] + } + ], + "source": [ + "reset()\n", + "load(\"truncated.py\")\n", + "A = matrix(ZZ,[[999, 18, 625, 416, 773]])\n", + "b = vector(ZZ, [1415])\n", + "c = vector(ZZ, (252, 537, 965, 237, 724))\n", + "u = vector(ZZ,5*[1])\n", + "\n", + "vv, g = bubu(A,b,c,u)" + ] + }, + { + "cell_type": "code", + "execution_count": 408, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[(1, 0, 0, 0, 0),\n", + " (0, 1, 0, 0, 0),\n", + " (0, 0, 1, 0, 0),\n", + " (0, 0, 0, 1, 0),\n", + " (0, 0, 0, 0, 1),\n", + " (0, 0, 0, -1, 1),\n", + " (0, 0, 0, -2, 1),\n", + " (0, 0, 1, 1, -1),\n", + " (0, 0, 1, 0, -1),\n", + " (0, 1, 0, -1, 0),\n", + " (-1, 0, 1, 0, 0),\n", + " (0, 1, 0, 1, -1),\n", + " (-1, 0, 0, 0, 1),\n", + " (0, -1, 0, 0, 1),\n", + " (0, 2, 0, 0, -1),\n", + " (0, 0, 1, -1, 0),\n", + " (0, 0, 1, -2, 0),\n", + " (0, -1, 1, -1, 0),\n", + " (1, 0, 0, -1, 0),\n", + " (-1, 0, 0, 2, 0),\n", + " (-1, 1, 0, 1, 0),\n", + " (0, -1, 1, 0, 0),\n", + " (0, 2, -1, 0, 0),\n", + " (-1, 1, 0, 0, 0)]" + ] + }, + "execution_count": 408, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "g.vectors" + ] + }, + { + "cell_type": "code", + "execution_count": 409, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 409, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(g.vectors)" + ] + }, + { + "cell_type": "code", + "execution_count": 410, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "22" + ] + }, + "execution_count": 410, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "GG=load('objeto')\n", + "len(GG)" + ] + }, + { + "cell_type": "code", + "execution_count": 411, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[-1 0 0 0 0]\n", + "[-1 0 0 1 0]\n", + "[ 0 -2 0 0 1]\n", + "[ 0 -2 1 0 0]\n", + "[ 0 -1 0 -1 1]\n", + "[ 0 -1 0 0 0]\n", + "[ 0 -1 0 1 0]\n", + "[ 0 0 -1 0 0]\n", + "[ 0 0 -1 0 1]\n", + "[ 0 0 -1 1 0]\n", + "[ 0 0 -1 2 0]\n", + "[ 0 0 0 -1 0]\n", + "[ 0 0 0 0 -1]\n", + "[ 0 0 0 1 -1]\n", + "[ 0 0 0 2 -1]\n", + "[ 0 1 -1 0 0]\n", + "[ 0 1 -1 1 0]\n", + "[ 0 1 0 0 -1]\n", + "[ 1 -1 0 0 0]\n", + "[ 1 0 -1 0 0]\n", + "[ 1 0 0 -2 0]\n", + "[ 1 0 0 0 -1]\n" + ] + } + ], + "source": [ + "print matrix(GG).str()\n" ] }, { "cell_type": "code", - "execution_count": 160, + "execution_count": 412, "metadata": { "collapsed": false }, @@ -195,108 +315,88 @@ "name": "stdout", "output_type": "stream", "text": [ - "23 (1, 0, 0, 0, 0, 0, 0) True (3, 4, 5) True\n", - "15 (0, 1, 0, 0, 0, 0, 0) True (1, 5, 6) True\n", - "6 (0, 0, 1, 0, 0, 0, 0) True (11, 0, 1) True\n", - "7 (0, 0, 0, 1, 0, 0, 0) True (2, 1, 9) True\n", - "1 (0, 0, 0, 0, 1, 0, 0) True (3, 7, 2) True\n", - "53 (0, 0, 0, 0, 0, 1, 0) True (5, 4, 3) True\n", - "4 (0, 0, 0, 0, 0, 0, 1) True (3, 6, 3) True\n", - "49 (0, 0, 0, 0, 0, 1, -1) True (2, -2, 0) True\n", - "45 (0, 0, 0, 0, 0, 1, -2) True (-1, -8, -3) True\n", - "48 (0, 0, 0, 0, -1, 1, -1) True (-1, -9, -2) True\n", - "3 (0, 0, 0, 0, -1, 0, 1) True (0, -1, 1) True\n", - "2 (0, 0, 0, 0, -2, 0, 1) True (-3, -8, -1) True\n", - "4 (0, 0, 0, 1, 1, 0, -1) True (2, 2, 8) True\n", - "3 (0, 0, 0, 1, 0, 0, -1) True (-1, -5, 6) True\n", - "0 (0, 0, 0, -1, -1, 0, 2) True (1, 4, -5) True\n", - "2 (0, 0, 0, 1, -1, 0, -1) True (-4, -12, 4) True\n", - "1 (0, 0, 0, -1, 0, 0, 2) True (4, 11, -3) True\n", - "1 (0, 0, 0, 1, -2, 0, -1) True (-7, -19, 2) True\n", - "47 (0, 0, 0, -1, 1, 1, 0) True (6, 10, -4) True\n", - "46 (0, 0, 0, -1, 0, 1, 0) True (3, 3, -6) True\n", - "45 (0, 0, 0, -1, -1, 1, 0) True (0, -4, -8) True\n", - "6 (0, 0, 0, 1, -1, 0, 0) True (-1, -6, 7) True\n", - "39 (0, 0, 0, -2, 0, 1, 0) True (1, 2, -15) True\n", - "42 (0, 0, 0, -1, 0, 1, -1) True (0, -3, -9) True\n", - "32 (0, 0, 0, -3, 0, 1, 0) True (-1, 1, -24) True\n", - "25 (0, 0, 0, -4, 0, 1, 0) True (-3, 0, -33) True\n", - "24 (0, -1, 0, -2, 0, 1, 0) True (0, -3, -21) True\n", - "1 (0, 1, 0, -2, 0, 0, 0) True (-3, 3, -12) True\n", - "23 (0, -2, 0, 0, 0, 1, 0) True (3, -6, -9) True\n", - "8 (0, 1, 0, -1, 0, 0, 0) True (-1, 4, -3) True\n", - "16 (0, -2, 0, -1, 0, 1, 0) True (1, -7, -18) True\n", - "8 (0, -3, 0, 0, 0, 1, 0) True (2, -11, -15) True\n", - "26 (0, 2, 0, 0, 0, 0, -1) True (-1, 4, 9) True\n", - "7 (0, 4, 0, 0, 0, -1, 0) True (-1, 16, 21) True\n", - "19 (0, -2, 0, 0, 0, 1, -1) True (0, -12, -12) True\n", - "11 (0, 1, 0, 0, 0, 0, -1) True (-2, -1, 3) True\n", - "31 (0, -1, 0, -1, 0, 1, 0) True (2, -2, -12) True\n", - "1 (0, -3, 0, -1, 0, 1, 0) True (0, -12, -24) True\n", - "44 (0, 3, 0, 0, -1, 0, 0) True (0, 8, 16) True\n", - "37 (0, -1, 0, 0, -1, 1, 0) True (1, -8, -5) True\n", - "22 (0, -2, 0, 0, -1, 1, 0) True (0, -13, -11) True\n", - "14 (0, 1, 0, 0, -1, 0, 0) True (-2, -2, 4) True\n", - "10 (0, 1, 0, 0, -1, 0, -1) True (-5, -8, 1) True\n", - "38 (0, -1, 0, 0, 0, 1, 0) True (4, -1, -3) True\n", - "13 (0, -1, 0, 4, 0, 0, 0) True (7, -1, 30) True\n", - "18 (0, 2, 0, -1, -1, 0, -1) True (-6, -4, -2) True\n", - "4 (0, 1, 0, -1, 0, 0, -1) True (-4, -2, -6) True\n", - "6 (0, -1, 0, 3, 0, 0, 0) True (5, -2, 21) True\n", - "8 (0, 2, 0, -3, -1, 0, 0) True (-7, 0, -17) True\n", - "15 (0, 2, 0, -2, -1, 0, 0) True (-5, 1, -8) True\n", - "11 (0, 1, 0, -1, -1, 0, 1) True (-1, 3, -2) True\n", - "7 (0, 1, 0, 0, 0, 0, -2) True (-5, -7, 0) True\n", - "7 (0, 1, 0, -1, -1, 0, 0) True (-4, -3, -5) True\n", - "34 (0, -1, 0, 0, 0, 1, -1) True (1, -7, -6) True\n", - "43 (0, 0, -1, 0, 0, 1, -1) True (-9, -2, -1) True\n", - "9 (0, 1, -1, 0, 0, 0, 0) True (-10, 5, 5) True\n", - "2 (0, 0, -1, 1, 1, 0, 0) True (-6, 8, 10) True\n", - "1 (0, 0, 1, 0, -1, 0, -1) True (5, -13, -4) True\n", - "42 (0, 0, -2, 0, 1, 1, 0) True (-14, 11, 3) True\n", - "40 (0, 0, -1, -1, 0, 1, 0) True (-8, 3, -7) True\n", - "2 (0, 0, 1, 0, 0, 0, -1) True (8, -6, -2) True\n", - "41 (0, 0, -2, 0, 0, 1, 0) True (-17, 4, 1) True\n", - "1 (0, 0, -1, 1, 0, 0, 0) True (-9, 1, 8) True\n", - "5 (0, 0, 1, 0, -1, 0, 0) True (8, -7, -1) True\n", - "32 (0, -1, -1, 0, 0, 1, 0) True (-7, -1, -4) True\n", - "7 (0, -1, -1, 4, 0, 0, 0) True (-4, -1, 29) True\n", - "0 (0, -1, -1, 3, 0, 0, 0) True (-6, -2, 20) True\n", - "6 (0, 1, 2, -3, 0, 0, 0) True (17, 2, -19) True\n", - "5 (0, 0, 2, -1, 0, 0, 0) True (20, -1, -7) True\n", - "0 (0, 0, -1, 1, -1, 0, 0) True (-12, -6, 6) True\n", - "8 (0, 1, -1, 0, -1, 0, 0) True (-13, -2, 3) True\n", - "3 (0, 1, -2, 0, 0, 0, 0) True (-21, 5, 4) True\n", - "2 (0, 1, -2, 0, -1, 0, 0) True (-24, -2, 2) True\n", - "46 (0, 0, -1, 0, -1, 1, 0) True (-9, -3, 0) True\n", - "35 (0, 0, -3, 0, 0, 1, 0) True (-28, 4, 0) True\n", - "24 (-1, 0, -1, 0, 0, 1, 0) True (-9, 0, -3) True\n", - "11 (1, 0, -2, 0, 0, 0, 0) True (-19, 4, 3) True\n", - "13 (-2, 0, 1, 0, 0, 1, 0) True (10, -4, -6) True\n", - "33 (2, 0, -2, 0, -1, 0, 0) True (-19, 1, 6) True\n", - "22 (1, 0, 0, 0, -1, 0, 0) True (0, -3, 3) True\n", - "7 (-2, 0, 0, 0, 0, 1, 0) True (-1, -4, -7) True\n" + "(-1, 1, 0, 1, 0)\n", + "(0, 0, 1, 1, -1)\n" ] } ], "source": [ - "for i in vecs: print c*i, i, let(i,u), A*i, let(A*i,b)" + "for z in sorted(g.vectors):\n", + " if not (z in GG or -z in GG): print z" + ] + }, + { + "cell_type": "code", + "execution_count": 413, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "for z in GG:\n", + " if not (z in g.vectors or -z in g.vectors): print copy(z), g.reduce(z)" ] }, { "cell_type": "code", - "execution_count": 161, + "execution_count": 414, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "22" + ] + }, + "execution_count": 414, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "g.self_reduce()\n", + "len(g.vectors)" + ] + }, + { + "cell_type": "code", + "execution_count": 415, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "for z in GG:\n", + " if not (z in g.vectors or -z in g.vectors): \n", + " print copy(z), g.reduce(z)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 400, "metadata": { "collapsed": false }, "outputs": [], "source": [ + "reset()\n", "load(\"truncated.py\")" ] }, { "cell_type": "code", - "execution_count": 162, + "execution_count": 325, "metadata": { "collapsed": false }, @@ -305,23 +405,23 @@ "name": "stdout", "output_type": "stream", "text": [ - "787 criterion 1, 0 criterion 2, 1952 reductions, 974 non eligible, 52 equalities\n" + "2442 criterion 1, 447 criterion 2, 3734 criterion 3, 108 non eligible, 10 equalities, 280 reductions, of which 168 to zero\n" ] } ], "source": [ "#%%prun\n", "\n", - "A = matrix(ZZ, [[3,1,11,2,3,5,3], [4, 5, 0, 1, 7,4, 6], [5,6,1,9,2,3,3]])\n", - "c = vector(ZZ, [23,15,6,7,1,53,4])\n", - "b = vector(ZZ, [31,27,38])\n", - "u = vector(ZZ, 7*[1])\n", - "vects, g = bubu(A,b,c,u)" + "A1 = matrix(ZZ, [[3,1,11,2,3,5,3], [4, 5, 0, 1, 7,4, 6], [5,6,1,9,2,3,3]])\n", + "c1 = vector(ZZ, [23,15,6,7,1,53,4])\n", + "b1 = vector(ZZ, [10,11,12])\n", + "u1 = vector(ZZ, 7*[1])\n", + "vects, g = bubu(A1,b1,c1,u1)" ] }, { "cell_type": "code", - "execution_count": 163, + "execution_count": 326, "metadata": { "collapsed": false }, @@ -329,10 +429,10 @@ { "data": { "text/plain": [ - "77" + "119" ] }, - "execution_count": 163, + "execution_count": 326, "metadata": {}, "output_type": "execute_result" } @@ -343,7 +443,94 @@ }, { "cell_type": "code", - "execution_count": 165, + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 327, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "reset()\n", + "load(\"truncated.py\")" + ] + }, + { + "cell_type": "code", + "execution_count": 328, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "c1=vector(ZZ,(4, 1, 1, 3, 4, 2, 2, 2, 2, 3, 1, 3))\n", + "A1=matrix(ZZ, [[1, 0, 0, 3, 1, 3, 3, 2, 1, 1, 3, 3],\n", + " [0, 3, 2, 0, 3, 2, 2, 2, 3, 0, 1, 2],\n", + " [0, 1, 2, 2, 1, 2, 0, 1, 2, 0, 3, 3],\n", + " [3, 0, 1, 2, 0, 0, 1, 1, 0, 1, 3, 1]])\n", + "b1=vector(ZZ,(17, 2, 13, 9))\n", + "u1=vector(ZZ,(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1))\n", + "#v, g = bubu(A1,b1,c1,u1)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 329, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "reset()\n", + "load(\"truncated.py\")\n", + "#v, g = bubu(B,b2,c2,u2)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "## Ejemplo de Ucha" + ] + }, + { + "cell_type": "code", + "execution_count": 347, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "def load_42_matrix(fname):\n", + " \"\"\"docstring for load_42_matrix\"\"\"\n", + " with open(fname) as f:\n", + " s=f.read().splitlines()\n", + " return [line_to_list(l) for l in s[1:]]\n", + "def line_to_list(s):\n", + " \"\"\"docstring for line_to_list\"\"\"\n", + " return [Integer(i) for i in s.strip().split()]\n", + "\n", + "Ap = matrix(matrix(ZZ, load_42_matrix(\"ejemploucha/ejemplosoto.mat\"))[0][:5])\n", + "cp = -vector(ZZ, load_42_matrix(\"ejemploucha/ejemplosoto.cost\")[0])[:5]\n", + "zsol = vector(ZZ,load_42_matrix(\"ejemploucha/ejemplosoto.zsol\")[0])\n", + "\n", + "b = vector(ZZ,[1415])\n", + "u = vector(ZZ, 5*[1])" + ] + }, + { + "cell_type": "code", + "execution_count": 348, "metadata": { "collapsed": false }, @@ -351,102 +538,339 @@ { "data": { "text/plain": [ - "[(1, 0, 0, 0, 0, 0, 0),\n", - " (0, 1, 0, 0, 0, 0, 0),\n", - " (0, 0, 1, 0, 0, 0, 0),\n", - " (0, 0, 0, 1, 0, 0, 0),\n", - " (0, 0, 0, 0, 1, 0, 0),\n", - " (0, 0, 0, 0, 0, 1, 0),\n", - " (0, 0, 0, 0, 0, 0, 1),\n", - " (0, 0, 0, 0, 0, 1, -1),\n", - " (0, 0, 0, 0, -1, 1, -1),\n", - " (0, 0, 0, -1, 0, 1, -1),\n", - " (0, 0, 0, 1, -1, 0, 0),\n", - " (0, 0, 0, 1, -1, 0, -1),\n", - " (0, 0, 0, -1, 0, 1, 0),\n", - " (0, 0, 0, 1, 0, 0, -1),\n", - " (0, 0, 0, 0, -1, 0, 1),\n", - " (0, 0, 1, 0, 1, 0, -1),\n", - " (0, 0, -1, 1, -1, 0, 0),\n", - " (0, 0, 1, -1, 0, 0, 1),\n", - " (0, 0, -1, 0, 0, 1, -1),\n", - " (0, 0, -1, -1, 0, 1, 0),\n", - " (0, 0, 1, 0, -1, 0, 0),\n", - " (0, 0, 1, 0, 0, 0, -1),\n", - " (0, 0, -1, 1, 0, 0, 0),\n", - " (0, 0, 1, 0, -1, 0, -1),\n", - " (0, 0, -1, 0, 0, 1, 0),\n", - " (0, 0, -1, 0, -1, 1, 0),\n", - " (0, 0, 0, -1, -1, 1, 0),\n", - " (0, -1, -1, 0, 0, 1, 0),\n", - " (0, 1, 1, -1, -1, 0, 0),\n", - " (0, 1, 0, -1, 0, 0, 1),\n", - " (0, 1, 1, -1, 0, 0, 0),\n", - " (0, 1, 0, -1, 1, 0, 0),\n", - " (0, 1, 0, -1, 0, 0, 0),\n", - " (0, -1, 0, 0, -1, 1, 0),\n", - " (0, 1, -1, 0, 0, 0, 0),\n", - " (0, -1, 0, -1, 0, 1, 0),\n", - " (0, 1, 0, 0, -1, 0, 0),\n", - " (0, 1, -1, 0, 0, 0, -1),\n", - " (0, -1, 0, 0, 0, 1, 1),\n", - " (0, 1, 0, -1, 0, 0, -1),\n", - " (0, 1, 0, -1, -1, 0, 0),\n", - " (0, -1, 0, 0, 0, 1, 0),\n", - " (0, 1, -1, 0, -1, 0, 0),\n", - " (0, 1, -1, 0, -1, 0, -1),\n", - " (1, -1, 0, 0, 1, 0, 0),\n", - " (-1, 0, 0, 0, -1, 1, 0),\n", - " (-1, 0, 0, 0, 0, 1, 0),\n", - " (1, -1, 0, 0, 0, 0, 0),\n", - " (-1, 0, 0, -1, 0, 1, 0),\n", - " (1, 0, -1, 0, 0, 0, -1),\n", - " (1, -1, -1, 0, 1, 0, 0),\n", - " (0, 1, 0, 0, -1, 0, -1),\n", - " (1, 0, 0, 0, 0, 0, -1),\n", - " (0, 1, 0, 0, 0, 0, -1),\n", - " (1, -1, -1, 0, 0, 0, 0),\n", - " (1, -1, 0, -1, 0, 0, 0),\n", - " (-1, 0, -1, 1, 0, 1, 0),\n", - " (1, 0, 0, -1, 0, 0, -1),\n", - " (1, -1, 0, 0, 0, 0, -1),\n", - " (-1, 0, -1, 0, 0, 1, 1),\n", - " (1, 0, 0, 0, -1, 0, 0),\n", - " (-1, -1, 0, 0, 0, 1, 0),\n", - " (1, 0, 0, -1, 0, 0, 0),\n", - " (1, -1, 0, 0, -1, 0, 0),\n", - " (-1, 0, -1, 0, 1, 1, 0),\n", - " (1, 0, 0, 0, -1, 0, -1),\n", - " (1, 0, -1, 0, 0, 0, 0),\n", - " (-1, 0, 0, 0, 0, 1, -1),\n", - " (1, 0, 0, -1, -1, 0, 1),\n", - " (1, 0, 0, -1, -1, 0, 0),\n", - " (1, 0, -1, -1, 0, 0, 1),\n", - " (1, 0, -1, -1, 1, 0, 0),\n", - " (1, 0, -1, -1, 0, 0, 0),\n", - " (-1, 0, -1, 0, 0, 1, 0),\n", - " (1, 0, -1, 0, -1, 0, 0),\n", - " (0, -1, 0, 0, 0, 1, -1),\n", - " (0, 0, 0, 0, -1, 1, 0)]" + "(252, 537, 965, 237, 724, 0, 0, 0, 0, 0, 0)" ] }, - "execution_count": 165, + "execution_count": 348, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "vects" + "\n", + "-vector(ZZ, load_42_matrix(\"ejemploucha/ejemplosoto.cost\")[0])" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 349, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[999 18 625 416 773 0 0 0 0 0 1]\n", + "[ 1 0 0 0 0 1 0 0 0 0 0]\n", + "[ 0 1 0 0 0 0 1 0 0 0 0]\n", + "[ 0 0 1 0 0 0 0 1 0 0 0]\n", + "[ 0 0 0 1 0 0 0 0 1 0 0]\n", + "[ 0 0 0 0 1 0 0 0 0 1 0]" + ] + }, + "execution_count": 349, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "AAA = matrix(ZZ, load_42_matrix(\"ejemploucha/ejemplosoto.mat\"))\n", + "AAA" + ] + }, + { + "cell_type": "code", + "execution_count": 350, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(1415, 1, 1, 1, 1, 1)" + ] + }, + "execution_count": 350, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "AAA*zsol" + ] + }, + { + "cell_type": "code", + "execution_count": 351, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "([999 18 625 416 773],\n", + " (252, 537, 965, 237, 724),\n", + " (0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1415))" + ] + }, + "execution_count": 351, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Ap, cp, zsol" + ] + }, + { + "cell_type": "code", + "execution_count": 352, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "GG = matrix(ZZ, load_42_matrix(\"ejemploucha/ejemplosoto.gro\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 353, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[-1 0 0 0 0]\n", + "[-1 0 0 1 0]\n", + "[ 0 -1 0 -1 1]\n", + "[ 0 -1 0 0 0]\n", + "[ 0 -1 0 1 0]\n", + "[ 0 0 -1 0 0]\n", + "[ 0 0 -1 0 1]\n", + "[ 0 0 -1 1 0]\n", + "[ 0 0 0 -1 0]\n", + "[ 0 0 0 0 -1]\n", + "[ 0 0 0 1 -1]\n", + "[ 0 1 -1 0 0]\n", + "[ 0 1 -1 1 0]\n", + "[ 0 1 0 0 -1]\n", + "[ 1 -1 0 0 0]\n", + "[ 1 0 -1 0 0]\n", + "[ 1 0 0 0 -1]" + ] + }, + "execution_count": 353, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "gg = GG.submatrix(0,0,ncols=5)\n", + "gg" + ] + }, + { + "cell_type": "code", + "execution_count": 354, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(17, 5)" + ] + }, + "execution_count": 354, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "gg.dimensions()" + ] + }, + { + "cell_type": "code", + "execution_count": 355, "metadata": { "collapsed": true }, "outputs": [], - "source": [] + "source": [ + "load(\"truncated.py\")" + ] + }, + { + "cell_type": "code", + "execution_count": 356, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "74 criterion 1, 9 criterion 2, 72 criterion 3, 8 non eligible, 0 equalities, 27 reductions, of which 12 to zero\n" + ] + } + ], + "source": [ + "\n", + "vecs, g = bubu(Ap,b,cp,u)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 357, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[(1, 0, 0, 0, 0),\n", + " (0, 1, 0, 0, 0),\n", + " (0, 0, 1, 0, 0),\n", + " (0, 0, 0, 1, 0),\n", + " (0, 0, 0, 0, 1),\n", + " (0, 0, 0, -1, 1),\n", + " (0, 0, 1, 1, -1),\n", + " (0, 1, -1, -1, 1),\n", + " (-1, 0, 1, 0, 0),\n", + " (0, 1, 0, 1, -1),\n", + " (-1, 0, 0, 0, 1),\n", + " (0, 0, 1, 0, -1),\n", + " (0, -1, 0, 0, 1),\n", + " (0, 0, 1, -1, 0),\n", + " (0, -1, 1, -1, 0),\n", + " (0, 1, 0, -1, 0),\n", + " (1, 0, 0, -1, 0),\n", + " (-1, 1, 0, 1, 0),\n", + " (0, -1, 1, 0, 0),\n", + " (-1, 1, 0, 0, 0)]" + ] + }, + "execution_count": 357, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vecs" + ] + }, + { + "cell_type": "code", + "execution_count": 358, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "20" + ] + }, + "execution_count": 358, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(g.vectors)" + ] + }, + { + "cell_type": "code", + "execution_count": 359, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6 (0, 0, 1, 1, -1)\n", + "7 (0, 1, -1, -1, 1)\n", + "17 (-1, 1, 0, 1, 0)\n" + ] + } + ], + "source": [ + "for i,v in enumerate(vecs): \n", + " if not (v in gg or -v in gg): \n", + " print i,v" + ] + }, + { + "cell_type": "code", + "execution_count": 360, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "for w in gg:\n", + " if not (w in vecs or -w in vecs): print w" + ] + }, + { + "cell_type": "code", + "execution_count": 361, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "g.self_reduce()" + ] + }, + { + "cell_type": "code", + "execution_count": 362, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "for w in gg:\n", + " if not (w in g.vectors or -w in g.vectors): print w" + ] + }, + { + "cell_type": "code", + "execution_count": 363, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "(17, (17, 5))" + ] + }, + "execution_count": 363, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(g.vectors), gg.dimensions()" + ] }, { "cell_type": "code", @@ -460,7 +884,7 @@ ], "metadata": { "kernelspec": { - "display_name": "SageMath 7.1", + "display_name": "SageMath 7.5.1", "language": "", "name": "sagemath" }, @@ -474,7 +898,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.10" + "version": "2.7.13" } }, "nbformat": 4, diff --git a/truncated.py b/truncated.py index da82c4a..91d5f5b 100755 --- a/truncated.py +++ b/truncated.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from collections import deque - +import pdb def getz(v): """Check if v is greater or equal than zero, component-wise.""" @@ -24,38 +24,75 @@ def let(a,b): if a[i]>b[i]: return False return True - + def let_pp(a,b): - "True if and only if a^+ is less or equal than b^+." + "True if and only if a^+ is less than or equal b^+." for i in xrange(len(a)): if a[i]>0 and a[i]>max(b[i], 0): return False return True - + def let_pm(a,b): "True if and only if a^+ is less or equal than b^-." for i in xrange(len(a)): if a[i]>0 and a[i]>max(-b[i], 0): return False return True - + def let_mp(a,b): "True if and only if a^- is less or equal than b^+." for i in xrange(len(a)): if a[i]<0 and -a[i]>max(b[i], 0): return False return True - + def let_mm(a,b): "True if and only if a^- is less or equal than b^-." for i in xrange(len(a)): if a[i]<0 and -a[i]>max(-b[i], 0): return False return True + +def disjoint_pp(v, w): + """true if v^+ and w^+ have disjoint support.""" + return not set(i for i in xrange(len(v)) if v[i]>0).intersection( + j for j in xrange(len(w)) if w[j]>0) +def disjoint_mm(v, w): + """true if v^- and w^- have disjoint support.""" + # return not set(i for i in xrange(len(v)) if v[i]<0).intersection( + # j for j in xrange(len(w)) if w[j]<0) + return not bool(set(i for (i,vi) in enumerate(v) if vi<0).intersection( + j for (j,wi) in enumerate(w) if wi<0)) + +def max_ppp(z, u, w): + """check that z^+ ≤ u^+ ∨ v^+""" + for l in xrange(len(z)): + if z[l]>0 and z[l]> max(u[l],w[l],0): + return False + return True + +def max_mmm(z, u, w): + """check that z^- ≤ u^- ∨ v^-""" + for l in xrange(len(z)): + if z[l]<0 and -z[l]>max(-u[l],-w[l],0): + return False + return True + +def ne_max_max(z, u, w): + """check that z^+ ∨ u^+ ≠ u^+ ∨ w^+""" + for l in xrange(len(z)): + if max(z[l], u[l],0) != max(u[l], w[l],0): + return True + return False + +def ne_max_max_minus(z, u, w): + """check that z^- ∨ u^- ≠ u^- ∨ w^-""" + for l in xrange(len(z)): + if max(-z[l], -u[l],0) != max(-u[l], -w[l],0): + return True + return False -def standard_basis(n): - return identity_matrix(ZZ,n).rows() def pm_split(v): @@ -70,12 +107,12 @@ def pm_split(v): um[i]=-a return vector(ZZ,up), vector(ZZ,um) - + class PartialBasis(object): """docstring for PartialBasis""" def __init__(self, A, c, b, u): super(PartialBasis, self).__init__() - self.n = A.dimensions()[1] + self.n = A.dimensions()[1] self.A = A self.c = c self.b = b @@ -84,13 +121,12 @@ def __init__(self, A, c, b, u): self.cv = [] self.Av = [] self.pairs = [] - self.psupp = [] for e in identity_matrix(ZZ,self.n).rows(): self.add_element(e) - - def add_element(self, v, check=True): + + def add_element(self, v): """ - add element e to partial basis, update critical pairs to be computed, + add element e to partial basis, update critical pairs to be computed, and precompute as much stuff as possible for reduction. """ cv = self.c*v @@ -98,90 +134,160 @@ def add_element(self, v, check=True): l = len(self.vectors) self.vectors.append(e) self.cv.append(abs(cv)) - self.Av.append(A*e) - self.psupp.append(set(e.support())) + self.Av.append(self.A*e) if l: # true if this is not the first vector for i in xrange(l): self.pairs.append((i,l)) - - + + def pop_element(self, i): + self.vectors.pop(i) + self.cv.pop(i) + self.Av.pop(i) + # for (j,p) in self.pairs: + # if i in p: + # self.pairs.pop(j) + def criterion_1(self, i, j): - """True if (i,j) is skipabble.""" - t = len(self.psupp[i].intersection(self.psupp[j]))==0 - return t - - def max(self, i, j): - """docstring for max""" - return vector(ZZ, [max(self.vecp[i][k],self.vecp[j][k]) for k in xrange(self.n)]) - + """True if (i,j) is skipabble: + The S-poly of the pair (i,j) is skippable if + its leading terms are disjoint. + """ + # print self.vectors[i], self.vectors[j], self.Av[i], self.Av[j] + return ( + (disjoint_pp(self.Av[i], self.Av[j])) and + disjoint_pp(self.vectors[i], self.vectors[j]) and + disjoint_mm(self.vectors[i], self.vectors[j]) + ) + + def criterion_3(self, i, j): + """Malkin's criterion.""" + # print self.vectors[i], self.vectors[j], self.Av[i], self.Av[j] + return ( + (not disjoint_mm(self.Av[i], self.Av[j])) or + (not disjoint_pp(self.vectors[i], self.vectors[j])) or + (not disjoint_mm(self.vectors[i], self.vectors[j])) + ) + # return ( + # (not disjoint_mm(self.Av[i], self.Av[j])) or + # (not disjoint_mm(self.vectors[i], self.vectors[j])) + # ) + + def criterion_2(self, i, j): """Gebauer and Möller""" # it is assumed i:", v l = len(self.vectors) - indices = deque(range(l)) + if by is None: + indices = deque(range(l)) + else: + indices = deque(by) + l = len(indices) i = 0 + # w = copy(v) w = v while i100: break - i, j = g.pop() - if g.criterion_1(i,j): + # if len(g.vectors)>160: break + i, j = g.next_pair() + + if g.criterion_1(i,j): c1 += 1 - next - # if g.criterion_2(i,j): - # c2 += 1 - # next - + # print "c1", g.vectors[i]-g.vectors[j] + continue + + if g.criterion_3(i,j): + c3 += 1 + # print "c3", g.vectors[i]-g.vectors[j] + continue + + if g.criterion_2(i,j): # (Simplified) Gebauer and Möller criterion + c2 += 1 + # print "c2", g.vectors[i]-g.vectors[j] + continue - cv = g.cv[i] - cw = g.cv[j] - if cv == cw: - equ +=1 - next - elif cw < cv: + if g.cv[j] == g.cv[i]: # ignore (Is this criterion 4?). + equ += 1 + continue + + if g.cv[j] < g.cv[i]: # set them in c-order i, j = j, i + # At this point, cv < cw. # 2.2.1 - #if g.eligible[i]: r = g.vectors[j]-g.vectors[i] Ar = A*r - # rp,rm = pm_split(r) - if let_pp(r,u) and let_mp(r,u) and let_pp(Ar,b) and let_mp(Ar,b) : + # Changed criterion!!!! + # my criterion + # if let_pp(r,u) and let_mp(r,u) and let_pp(Ar,b) and let_mp(Ar,b) : + # T-W criterion + if let_pp(g.vectors[i],g.u) and let_mp(g.vectors[i],u) and let_pp(g.Av[i],g.b) and let_mp(g.Av[i], b): rx +=1 + if (rx%1000) == 0: + print "reduction: %s, basis: %s." % (rx, len(g.vectors)) c = g.reduce(r) if not isz(c): g.add_element(c) - # print "+", c - # print g.vectors + else: + z += 1 else: + # print r elig += 1 - next - - print "%s criterion 1, %s criterion 2, %s reductions, %s non eligible, %s equalities" % (c1, c2, rx, elig, equ) + continue + + print "%s criterion 1, %s criterion 2, %s criterion 3, %s non eligible, %s equalities, %s reductions, of which %s to zero" % (c1, c2, c3, elig, equ, rx, z) return g.vectors, g - - - - + + + + A1 = matrix(ZZ, [[3,1,11,2,3,5,3], [4, 5, 0, 1, 7,4, 6], [5,6,1,9,2,3,3]]) c1 = vector(ZZ, [23,15,6,7,1,53,4]) b1 = vector(ZZ, [31,27,38]) u1 = vector(ZZ, 7*[38]) - \ No newline at end of file + + +B = matrix(ZZ, [ +[9, 6, 6, 8, 3, 6, 2, 4, 6, 3, 9, 4, 4, 8, 6, 9, 4, 2, 8, 8], +[8, 8, 0, 5, 4, 4, 7, 0, 2, 3, 0, 6, 7, 7, 0, 6, 7, 8, 6, 0], +[0, 9, 4, 1, 2, 0, 6, 5, 8, 5, 5, 5, 0, 0, 9, 3, 1, 8, 4, 8], +[5, 0, 1, 6, 0, 7, 7, 5, 8, 0, 2, 7, 3, 9, 0, 6, 9, 8, 7, 3], +[3, 0, 2, 7, 5, 8, 1, 2, 1, 5, 7, 8, 3, 8, 4, 3, 6, 2, 9, 3], +]) +c2 = vector(ZZ,[3, 2, 9, 1, 7, 5, 6, 2, 7, 8, 6, 9, 2, 6, 8, 7, 6, 2, 2, 1]) +b2 = vector(ZZ, 5*[50]) +u2 = vector(ZZ, 20*[1]) + From ca465526c54cf032527f04b6e14ad8f5981f2f92 Mon Sep 17 00:00:00 2001 From: anteprandium Date: Fri, 31 Mar 2017 12:28:26 +0200 Subject: [PATCH 10/15] reduction recycles vectors and matrices --- truncated.py | 129 ++++++++++++++++++++++++++------------------------- 1 file changed, 67 insertions(+), 62 deletions(-) diff --git a/truncated.py b/truncated.py index 91d5f5b..25892a8 100755 --- a/truncated.py +++ b/truncated.py @@ -6,7 +6,7 @@ def getz(v): """Check if v is greater or equal than zero, component-wise.""" # return all(vi>=0 for vi in v) #(Slower by a factor of 2) - for vi in v: + for vi in v: if vi<0: return False return True @@ -57,7 +57,7 @@ def disjoint_pp(v, w): """true if v^+ and w^+ have disjoint support.""" return not set(i for i in xrange(len(v)) if v[i]>0).intersection( j for j in xrange(len(w)) if w[j]>0) - + def disjoint_mm(v, w): """true if v^- and w^- have disjoint support.""" # return not set(i for i in xrange(len(v)) if v[i]<0).intersection( @@ -68,7 +68,7 @@ def disjoint_mm(v, w): def max_ppp(z, u, w): """check that z^+ ≤ u^+ ∨ v^+""" for l in xrange(len(z)): - if z[l]>0 and z[l]> max(u[l],w[l],0): + if z[l]>0 and z[l]>max(u[l],w[l],0): return False return True @@ -138,7 +138,7 @@ def add_element(self, v): if l: # true if this is not the first vector for i in xrange(l): self.pairs.append((i,l)) - + def pop_element(self, i): self.vectors.pop(i) self.cv.pop(i) @@ -146,17 +146,17 @@ def pop_element(self, i): # for (j,p) in self.pairs: # if i in p: # self.pairs.pop(j) - + def criterion_1(self, i, j): """True if (i,j) is skipabble: - The S-poly of the pair (i,j) is skippable if + The S-poly of the pair (i,j) is skippable if its leading terms are disjoint. """ # print self.vectors[i], self.vectors[j], self.Av[i], self.Av[j] return ( (disjoint_pp(self.Av[i], self.Av[j])) and - disjoint_pp(self.vectors[i], self.vectors[j]) and - disjoint_mm(self.vectors[i], self.vectors[j]) + disjoint_pp(self.vectors[i], self.vectors[j]) and + disjoint_mm(self.vectors[i], self.vectors[j]) ) def criterion_3(self, i, j): @@ -196,58 +196,87 @@ def criterion_2(self, i, j): and ne_max_max(Av[k], Av[i], Av[j]) and ne_max_max(v[k],v[i],v[j]) and ne_max_max_minus(v[k], v[i], v[j]) and - ne_max_max(Av[k], Av[j], Av[i]) and ne_max_max(v[k],v[j],v[i]) and ne_max_max_minus(v[k], v[j], v[i]) + ne_max_max(Av[k], Av[j], Av[i]) and ne_max_max(v[k],v[j],v[i]) and ne_max_max_minus(v[k], v[j], v[i]) ): - + return True - + return False - - def reduce_by_ith(self, s, i): + + def reduce_by_ith(self, s, As, i): """ It modifies s in place!!! - If s is not reducible by vectors[i], return False. - Else, if s is reducible by vectors[i], return z reduced + If ±s is not reducible by vectors[i], return False. + Else, if s is reducible by vectors[i], return ±s reduced as many times as possible by vectors[i]. - Note that the return value might be the zero vector, so + Note that the return value might be the zero vector, so test reduce_by_ith(i,j) is False for non reducibility. - + """ round = 0 v = self.vectors[i] Av = self.Av[i] w = s + Aw = As - if isz(w): return w + if isz(w): return w, Aw while True: - Aw = self.A*w if let_pp(v,w) and let_mm(v,w) and let_pp(Av, Aw): # w is reducible round += 1 - # w = w-v + # w = w-v, but modify in place. for k in xrange(self.n): w[k]-=v[k] + # Aw = Aw-Av + for k in xrange(len(Aw)): + Aw[k] -= Av[k] elif let_pm(v,w) and let_mp(v,w) and let_pm(Av, Aw): # -w is reducible - # print "-", w, -w-v round += 1 - # w = -w-v + # w = -w-v for k in xrange(self.n): w[k]=-w[k]-v[k] + # Aw = -A*w-A*v + for k in xrange(len(Aw)): + Aw[k] = -Aw[k]-Av[k] else: # no reducibility break if round == 0: - return False + return False, False else: - # print "%s rounds !" % round - return w + return w, Aw + + + def reduce(self, v, by=None): + """reduce""" + l = len(self.vectors) + if by is None: + indices = deque(range(l)) + else: + indices = deque(by) + l = len(indices) + i = 0 + w = v + Aw = self.A*w + while i:", v - l = len(self.vectors) - if by is None: - indices = deque(range(l)) - else: - indices = deque(by) - l = len(indices) - i = 0 - # w = copy(v) - w = v - while i160: break + # if len(g.vectors)>200: break i, j = g.next_pair() - + if g.criterion_1(i,j): c1 += 1 # print "c1", g.vectors[i]-g.vectors[j] @@ -348,27 +352,28 @@ def bubu(A,b,c,u): # print "c3", g.vectors[i]-g.vectors[j] continue - if g.criterion_2(i,j): # (Simplified) Gebauer and Möller criterion - c2 += 1 - # print "c2", g.vectors[i]-g.vectors[j] - continue - + # This might be wrong! if g.cv[j] == g.cv[i]: # ignore (Is this criterion 4?). equ += 1 continue + if g.criterion_2(i,j): # Gebauer and Möller criterion + c2 += 1 + # print "c2", g.vectors[i]-g.vectors[j] + continue + if g.cv[j] < g.cv[i]: # set them in c-order i, j = j, i - + # At this point, cv < cw. # 2.2.1 r = g.vectors[j]-g.vectors[i] - Ar = A*r # Changed criterion!!!! # my criterion - # if let_pp(r,u) and let_mp(r,u) and let_pp(Ar,b) and let_mp(Ar,b) : + Ar = A*r + if let_pp(r,u) and let_mp(r,u) and let_pp(Ar,b) and let_mp(Ar,b) : # T-W criterion - if let_pp(g.vectors[i],g.u) and let_mp(g.vectors[i],u) and let_pp(g.Av[i],g.b) and let_mp(g.Av[i], b): + # if let_pp(g.vectors[i],g.u) and let_mp(g.vectors[i],g.u) and let_pp(g.Av[i],g.b) and let_mp(g.Av[i], g.b) : rx +=1 if (rx%1000) == 0: print "reduction: %s, basis: %s." % (rx, len(g.vectors)) From 453e55e7f0bb90a90d58ef39ffa6200a06c3cad4 Mon Sep 17 00:00:00 2001 From: anteprandium Date: Mon, 3 Apr 2017 16:00:48 +0200 Subject: [PATCH 11/15] fixed the criterion --- resolutor.py | 72 +++++++++++++++++++++++ truncated.py | 162 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 183 insertions(+), 51 deletions(-) create mode 100644 resolutor.py diff --git a/resolutor.py b/resolutor.py new file mode 100644 index 0000000..fb10630 --- /dev/null +++ b/resolutor.py @@ -0,0 +1,72 @@ +import subprocess +def run_4ti2(command, data, results): + """Run 4ti2 and """ + #cleanup_42() + setup_42(data) + s = subprocess.call( + ["./%s %s"% (command, TMPF)], + shell=True, + # stdout=subprocess.PIPE, + # stderr=subprocess.PIPE, + ) + if s: + raise RuntimeError("ha fallado 4ti2") + + return [load_42_matrix(r) for r in results] + +def load_42_matrix(ext): + """docstring for load_42_matrix""" + with open(TMPF+ext) as f: + s=f.read().splitlines() + return [line_to_list(l) for l in s[1:]] + + +def write_42_file(ext, string): + """docstring for write_42""" + fname = TMPF + ext + with open(fname, 'w') as f: + f.write(string) + +def matrix_to_42(A): + """Print a representation of matrix M as 4ti2 input. M should be an integer matrix.""" + M = matrix(ZZ,A) + n, m = M.dimensions() + return "%s %s\n" % (n,m) + "\n".join([row_to_42(r) for r in M.rows()]) + "\n" + +def row_to_42(r): + """Convert a vector to 4ti2 input format. Should be an integer vector""" + return " ".join([str(i) for i in r]) + +def setup_42(data): + for (k, s) in data.iteritems(): + write_42_file(k,s) + + +def bigsolve(A,b,c,u): + + (d,n)=A.dimensions() + + lower = identity_matrix(n).augment(zero_matrix(n,d)).augment(identity_matrix(n)) + + bigA = A.augment(identity_matrix(d)).augment(zero_matrix(d,n)).stack(lower) + bigb = matrix(b).augment(matrix(c)) + bigc = matrix(c).augment(zero_matrix(1,n+d)) + + + zsol = vector(ZZ,n*[0]+list(b)+n*[1]) + #bigA, bigb, bigc, zsol + data = { + ".mat": matrix_to_42(bigA), + ".zsol": matrix_to_42(matrix(zsol)), + ".cost": matrix_to_42(-matrix(bigc)) + } + GG = matrix(ZZ,run_4ti2("../42/pruebas/groebner -t lp", data, [".gro"])[0])[:,0:n] + return GG.rows() + +def line_to_list(s): + """docstring for line_to_list""" + return [Integer(i) for i in s.strip().split()] + + +TMPF = "temporary_file__" + diff --git a/truncated.py b/truncated.py index 25892a8..02e6ade 100755 --- a/truncated.py +++ b/truncated.py @@ -1,7 +1,8 @@ #!/usr/bin/env python from collections import deque -import pdb + + def getz(v): """Check if v is greater or equal than zero, component-wise.""" @@ -12,14 +13,15 @@ def getz(v): def isz(v): """Check if v is zero. Slightly faster than .is_zero()""" - # return all(vi>=0 for vi in v) #(Slower by a factor of 2) + # # # return all(vi>=0 for vi in v) #(Slower by a factor of 2) for vi in v: if vi!=0: return False return True + # return v.is_zero() def let(a,b): - "True if and only if a is less or equal than b. Faster than zipping lists by a factor of 100" + "True if and only if a is less or equal than b. Faster than zipping lists" for i in xrange(len(a)): if a[i]>b[i]: return False @@ -112,7 +114,7 @@ class PartialBasis(object): """docstring for PartialBasis""" def __init__(self, A, c, b, u): super(PartialBasis, self).__init__() - self.n = A.dimensions()[1] + self.d, self.n = A.dimensions() self.A = A self.c = c self.b = b @@ -121,8 +123,14 @@ def __init__(self, A, c, b, u): self.cv = [] self.Av = [] self.pairs = [] + self.zerox = vector(ZZ,self.n*[0]) + self.zerob = vector(ZZ, self.d*[0]) for e in identity_matrix(ZZ,self.n).rows(): self.add_element(e) + + # def set_to_Au(self, v, u): + # """set vector v to A*u""" + def add_element(self, v): """ @@ -206,7 +214,7 @@ def criterion_2(self, i, j): def reduce_by_ith(self, s, As, i): """ - It modifies s in place!!! + It modifies s and As in place!!! If ±s is not reducible by vectors[i], return False. Else, if s is reducible by vectors[i], return ±s reduced @@ -235,15 +243,23 @@ def reduce_by_ith(self, s, As, i): # Aw = Aw-Av for k in xrange(len(Aw)): Aw[k] -= Av[k] + # # slower alternative: + # w -= v + # Aw -= Av elif let_pm(v,w) and let_mp(v,w) and let_pm(Av, Aw): # -w is reducible round += 1 - # w = -w-v + # w = -w-v for k in xrange(self.n): w[k]=-w[k]-v[k] # Aw = -A*w-A*v for k in xrange(len(Aw)): Aw[k] = -Aw[k]-Av[k] + # # slower: + # w *= -1 + # w -=v + # Aw *= -1 + # Av -= Av else: # no reducibility break @@ -251,6 +267,10 @@ def reduce_by_ith(self, s, As, i): if round == 0: return False, False else: + + + + return w, Aw @@ -265,6 +285,9 @@ def reduce(self, v, by=None): i = 0 w = v Aw = self.A*w + # Aw = copy(self.zerob) + # for k in xrange(self.d): + # Aw[k] = sum(self.A[k,l]*w[l] for l in xrange(self.n)) while i0: + up[i]=a + elif a<0: + um[i]=-a + return up, um + + def feasible(self, v): + """docstring for feasible""" + if let_pp(v,self.u) and let_mp(v,self.u): + avp, avm = pm_split(v) + return let(self.A*avp, self.b) and let(self.A*avm, self.b) + return False + + def order(self, i,j): + """ + Set i, j in gr-rev-lex order: + + vi > vj if c*vi > c*vj or + equality and the last nonzero coordinate of vi-vj is negative. + + We sort indices and not vectors so that we don't have to compute + c*v and c*v more than once. + """ + if self.cv[i]>self.cv[j]: + return (i,j) + elif self.cv[i] v[l] : + return (j,i) + elif u[l] < v[l] : + return (i,j) + # The vectors are equal. This should never happen: + raise RuntimeError("Vectors %s and %s are equal (%s and %s)" % (i,j,self.vectors[i], self.vectors[j])) + + + def bubu(A,b,c,u): @@ -335,8 +403,8 @@ def bubu(A,b,c,u): c3 = 0 rx = 0 elig = 0 - equ = 0 z = 0 + while g.unfinished(): # if len(g.vectors)>200: break @@ -344,36 +412,28 @@ def bubu(A,b,c,u): if g.criterion_1(i,j): c1 += 1 - # print "c1", g.vectors[i]-g.vectors[j] continue if g.criterion_3(i,j): c3 += 1 - # print "c3", g.vectors[i]-g.vectors[j] - continue - - # This might be wrong! - if g.cv[j] == g.cv[i]: # ignore (Is this criterion 4?). - equ += 1 continue if g.criterion_2(i,j): # Gebauer and Möller criterion c2 += 1 - # print "c2", g.vectors[i]-g.vectors[j] continue - if g.cv[j] < g.cv[i]: # set them in c-order - i, j = j, i + i,j = g.order(i,j) + # At this point, cv < cw. # 2.2.1 - r = g.vectors[j]-g.vectors[i] - # Changed criterion!!!! - # my criterion - Ar = A*r - if let_pp(r,u) and let_mp(r,u) and let_pp(Ar,b) and let_mp(Ar,b) : - # T-W criterion - # if let_pp(g.vectors[i],g.u) and let_mp(g.vectors[i],g.u) and let_pp(g.Av[i],g.b) and let_mp(g.Av[i], g.b) : + # r = g.vectors[i] + # r -= g.vectors[j] + r = copy(g.zerox) + for l in xrange(g.n): + r[l] = g.vectors[j][l]-g.vectors[i][l] + + if g.feasible(r): rx +=1 if (rx%1000) == 0: print "reduction: %s, basis: %s." % (rx, len(g.vectors)) @@ -387,7 +447,7 @@ def bubu(A,b,c,u): elig += 1 continue - print "%s criterion 1, %s criterion 2, %s criterion 3, %s non eligible, %s equalities, %s reductions, of which %s to zero" % (c1, c2, c3, elig, equ, rx, z) + print "%s criterion 1, %s criterion 2, %s criterion 3, %s non feasible, %s reductions, of which %s to zero" % (c1, c2, c3, elig, rx, z) return g.vectors, g From 83b24a551686d6021170420ae953ab181e1bc5bc Mon Sep 17 00:00:00 2001 From: anteprandium Date: Tue, 4 Apr 2017 14:01:39 +0200 Subject: [PATCH 12/15] Fixed binomial ordering; added p,m supports to precomputed data --- binomials.ipynb | 622 ++++++++++++++ binomials.py | 206 +++++ ejemploucha/ejemplosoto.cost | 2 + ejemploucha/ejemplosoto.gro | 18 + ejemploucha/ejemplosoto.mat | 7 + ejemploucha/ejemplosoto.zsol | 2 + obj3x7.sobj | Bin 0 -> 3469 bytes objeto.sobj | Bin 0 -> 590 bytes optimus_prime.ipynb | 1524 +++++++++++++++++----------------- problema_1.ipynb | 406 +++++---- resolutor.pyc | Bin 0 -> 2880 bytes roer.sobj | Bin 0 -> 3192 bytes temporary_file__.cost | 2 + temporary_file__.gro | 67 ++ temporary_file__.mat | 17 + temporary_file__.zsol | 2 + truncated.ipynb | 784 ++++++++++++----- truncated.py | 157 +++- 18 files changed, 2660 insertions(+), 1156 deletions(-) create mode 100644 binomials.ipynb create mode 100755 binomials.py create mode 100644 ejemploucha/ejemplosoto.cost create mode 100644 ejemploucha/ejemplosoto.gro create mode 100644 ejemploucha/ejemplosoto.mat create mode 100644 ejemploucha/ejemplosoto.zsol create mode 100644 obj3x7.sobj create mode 100644 objeto.sobj create mode 100644 resolutor.pyc create mode 100644 roer.sobj create mode 100644 temporary_file__.cost create mode 100644 temporary_file__.gro create mode 100644 temporary_file__.mat create mode 100644 temporary_file__.zsol diff --git a/binomials.ipynb b/binomials.ipynb new file mode 100644 index 0000000..40531e5 --- /dev/null +++ b/binomials.ipynb @@ -0,0 +1,622 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 24, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "\n", + "longitud = 50\n", + "numero = 50000\n", + "altura = 7\n", + "\n", + "vvv = [random_vector(ZZ, longitud, x=0, y=20) for i in range(numero)]\n", + "www = vvv[::-1]\n", + "zero = vector(ZZ,longitud*[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def minux(v):\n", + " for i in xrange(len(v)):\n", + " v[i] *=-1" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 loop, best of 3: 443 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "for v in vvv:\n", + " v=-v" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 loop, best of 3: 2.01 s per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "for v in vvv:\n", + " minux(v)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 loop, best of 3: 591 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "for v in vvv:\n", + " v *= -1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def pm_split(v):\n", + " \"\"\" slightly faster than pm_split2\"\"\"\n", + " l = len(v)\n", + " up = l*[0]\n", + " um = l*[0]\n", + " for i,a in enumerate(v):\n", + " if a>0:\n", + " up[i]=a\n", + " else:\n", + " um[i]=-a\n", + " return vector(ZZ,up), vector(ZZ,um)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def pm_split(v):\n", + " \"\"\" slightly faster than pm_split2\"\"\"\n", + " up = copy(zero)\n", + " um = copy(zero)\n", + " for i,a in enumerate(v):\n", + " if a>0:\n", + " up[i]=a\n", + " else:\n", + " um[i]=-a\n", + " return up, um\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "\n", + "def pm_split(v):\n", + " \"\"\" slightly faster than pm_split2\"\"\"\n", + " up = copy(zero)\n", + " um = copy(zero)\n", + " for i,a in enumerate(v):\n", + " if a>0:\n", + " up[i]=a\n", + " elif a<0:\n", + " um[i]=-a\n", + " return up, um\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 loop, best of 3: 3.3 s per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "for v in vvv:\n", + " pm_split(v)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "A = random_matrix(ZZ, 7, 25, x=1, y=15)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "A.apply_map?" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def less_or_equal(a,b):\n", + " \"True if and only if a is less or equal than b. Faster than zipping lists by a factor of 100\"\n", + " for i in xrange(len(a)):\n", + " if a[i]>b[i]:\n", + " return False\n", + " return True\n" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def less_or_equal2(a,b):\n", + " \"True if and only if a is less or equal than b. Faster than zipping lists by a factor of 100\"\n", + " for i,a in enumerate(a):\n", + " if a>b[i]:\n", + " return False\n", + " return True\n" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10 loops, best of 3: 64.2 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "for k in xrange(numero):\n", + " less_or_equal(vvv[k],www[k])" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10 loops, best of 3: 55.5 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "for k in xrange(numero):\n", + " less_or_equal2(vvv[k],www[k])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "def supports(v):\n", + " \"\"\"\n", + " Compute the positive and negative support of v\n", + " \"\"\"\n", + " psupp = []\n", + " nsupp = []\n", + " for (k, c) in enumerate(v):\n", + " if c>0:\n", + " psupp.append(k)\n", + " elif c<0:\n", + " nsupp.append(k)\n", + " return psupp, nsupp" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 loop, best of 3: 744 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "for i in xrange(numero):\n", + " supports(vvv[i])" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 loop, best of 3: 1.36 s per loop\n" + ] + } + ], + "source": [ + "%%timeit\n", + "for i in xrange(numero):\n", + " copy2(vvv[i],www[i])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "c = random_vector(ZZ,longitud, x=1, y=15)\n", + "A = random_matrix(ZZ, altura, longitud, x=0, y=50)\n", + "b = random_vector(ZZ, altura, x=90, y=150)\n", + "u = random_vector(ZZ, longitud, x=1, y=14)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "load(\"binomials.py\")" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "g = BinomialBasis(A,b,c,u)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Cost functions" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "# Cost function. Best is cost1\n", + "\n", + "from itertools import izip\n", + "\n", + "def cost1(v):\n", + " return c*v\n", + "\n", + "def cost2(v):\n", + " return sum(c[i]*v[i] for i in xrange(longitud))\n", + "\n", + "def cost3(v):\n", + " return sum(ci*vi for ci, vi in izip(c,v))\n", + "\n", + "def cost4(v):\n", + " return sum(ci*vi for ci, vi in zip(c,v))\n", + "\n", + "def cost5(v):\n", + " return sum(c[i]*v[i] for i in range(longitud))\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100 loops, best of 3: 8.95 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit \n", + "for v in zzz: \n", + " cost1(v)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10 loops, best of 3: 79.1 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit \n", + "for v in zzz: \n", + " cost2(v)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10 loops, best of 3: 83.3 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit \n", + "for v in zzz: \n", + " cost3(v)" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10 loops, best of 3: 98 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit \n", + "for v in zzz: \n", + " cost4(v)" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10 loops, best of 3: 93.2 ms per loop\n" + ] + } + ], + "source": [ + "%%timeit \n", + "for v in zzz: \n", + " cost5(v)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "SageMath 7.5.1", + "language": "", + "name": "sagemath" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.13" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/binomials.py b/binomials.py new file mode 100755 index 0000000..f47e386 --- /dev/null +++ b/binomials.py @@ -0,0 +1,206 @@ +#!/usr/bin/env python + + +class BinomialBasis(object): + """ + + Fastest way to compute cost: c*v + + + """ + def __init__(self, A, b,c, u): + super(BinomialBasis, self).__init__() + self.d, self.n = A.dimensions() + self.A = A + self.c = c + self.b = b + self.u = u + self.bins = [] # binomials + self.Abins = [] # A*v for v in binomials + self.bins_psupp = [] # positive support of binomial + self.bins_nsupp = [] # negative support of binomials + self.Abins_psupp = [] # positive support of Av + self.Abins_nsupp = [] # negative support of Av + self.cbins = [] # c*v for v in binomials + self.pairs = [] # pairs still to go. + self.zerox = vector(ZZ,self.n*[0]) # for fast copying. + self.zerob = vector(ZZ, self.d*[0]) # for fast copying. + + # + # + for e in identity_matrix(ZZ,self.n).rows(): + self.push_binomial(e) + + def supports(self, v): + """ + Compute the positive and negative support of v + """ + psupp = [] + nsupp = [] + for (k, c) in enumerate(v): + if c>0: + psupp.append(k) + elif c<0: + nsupp.append(k) + return psupp, nsupp + + + def push_binomial(self, v, Av=None): + """ + Add binomial v and associated data into place. + + May change sign of v and Av in place. + + """ + cost = self.c*v + if Av is None: + av = self.A*v + else: + av = av + + if cost<0: + # modify v and av in place. + for k in xrange(self.n): + v[k] = -v[k] + for k in xrange(self.d): + av[k] = -av[k] + + if cost == 0: + raise RuntimeError("zero cost vector %s. Deal with this." %v) + + p, n = self.supports(v) + ap, an = self.supports(av) + l = len(self.bins) + + self.bins.append(v) + self.cbins.append(abs(cost)) + self.Abins.append(av) + self.bins_psupp.append(p) + self.bins_nsupp.append(n) + self.Abins_psupp.append(ap) + self.Abins_nsupp.append(an) + + if l: # true if this is not the first vector + for i in xrange(l): + self.pairs.append((i,l)) + + def pop_binomials(i, pairs=True): + self.bins.pop(i) + self.cbins.pop(i) + self.Abins.pop(i) + self.bins_psupp.pop(i) + self.bins_nsupp.pop(i) + self.Abins_psupp.pop(i) + self.Abins_nsupp.pop(i) + if pairs: + for (k,p) in enumerate(self.pairs): + if i in p: + self.pairs.pop(k) + + def next_pair(self): + return self.pairs.pop[-1] + + def order(self, i,j): + """ + Set i, j in gr-rev-lex order: + + vi > vj if c*vi > c*vj or + equality and the last nonzero coordinate of vi-vj is negative. + + We sort indices and not vectors so that we don't have to compute + c*v and c*v more than once. + """ + if self.cbins[i]>self.cbins[j]: + return (i,j) + elif self.cbins[i] self.bins[l] : + return (j,i) + elif self.bins[l] < self.bins[l] : + return (i,j) + # The vectors are equal. This should never happen: + raise RuntimeError("Vectors %s and %s are equal (%s)" % (i,j,self.bins[i])) + + + def criterion_1(self, i,j): + if ( + bool(set.intersect(self.Abins_psupp[i], self.Abins_psupp[j])) or + bool(set.intersect(self.bins_nsupp[i], self.bins_nsupp[j])) or + bool(set.intersect(self.bins_psupp[i], self.bins_psupp[j])) + ): + return False + else: + return True + + def feasible(self, v): + """docstring for feasible""" + if self.less_or_equal_pp(v,self.b) and self.less_or_equal_mp(v,self.b): + avp, avm = pm_split(v) + return self.less_or_equal_pp(self.A*avp, self.b) and self.less_or_equal_pp(self.A*avm, self.b) + return False + + def pm_split(v): + """ slightly faster than pm_split2""" + up = copy(self.zerox) + um = copy(self.zerox) + for i,a in enumerate(v): + if a>0: + up[i]=a + elif a<0: + um[i]=-a + return up, um + + + + + def less_or_equal(self, a,b): + "True if and only if a is less or equal than b." + for (i,ai) in enumerate(a): + if ai>b[i]: + return False + return True + + def less_or_equal_pp(self, a,b): + "True if and only if a^+ is less or equal than b^+." + for (i,ai) in enumerate(a): + if ai>0 and ai>b[i]: + return False + return True + + def less_or_equal_mp(self, a,b): + "True if and only if a^+ is less or equal than b^+." + for (i,ai) in enumerate(a): + if ai<0 and -ai>b[i]: + return False + return True + + + + + + + def bu_buch(self): + """docstring for fname""" + skip_c1 = 0 + + + while self.pairs: + i,j = self.next_pair() + if criterion_1(i,j): + skip_c1 +=1 + continue + + i,j = self.order(i,j) + # fast r = ui-uj + r = copy(g.zerox) + for l in xrange(g.n): + r[l] = self.bins[i][l]-self.bins[j][l] + # end of fast r=ui-uj + if self.feasible(v): + + + + diff --git a/ejemploucha/ejemplosoto.cost b/ejemploucha/ejemplosoto.cost new file mode 100644 index 0000000..d030ada --- /dev/null +++ b/ejemploucha/ejemplosoto.cost @@ -0,0 +1,2 @@ +1 11 +-252 -537 -965 -237 -724 0 0 0 0 0 0 diff --git a/ejemploucha/ejemplosoto.gro b/ejemploucha/ejemplosoto.gro new file mode 100644 index 0000000..60500ae --- /dev/null +++ b/ejemploucha/ejemplosoto.gro @@ -0,0 +1,18 @@ +17 11 +-1 0 0 0 0 1 0 0 0 0 999 +-1 0 0 1 0 1 0 0 -1 0 583 + 0 -1 0 -1 1 0 1 0 1 -1 -339 + 0 -1 0 0 0 0 1 0 0 0 18 + 0 -1 0 1 0 0 1 0 -1 0 -398 + 0 0 -1 0 0 0 0 1 0 0 625 + 0 0 -1 0 1 0 0 1 0 -1 -148 + 0 0 -1 1 0 0 0 1 -1 0 209 + 0 0 0 -1 0 0 0 0 1 0 416 + 0 0 0 0 -1 0 0 0 0 1 773 + 0 0 0 1 -1 0 0 0 -1 1 357 + 0 1 -1 0 0 0 -1 1 0 0 607 + 0 1 -1 1 0 0 -1 1 -1 0 191 + 0 1 0 0 -1 0 -1 0 0 1 755 + 1 -1 0 0 0 -1 1 0 0 0 -981 + 1 0 -1 0 0 -1 0 1 0 0 -374 + 1 0 0 0 -1 -1 0 0 0 1 -226 diff --git a/ejemploucha/ejemplosoto.mat b/ejemploucha/ejemplosoto.mat new file mode 100644 index 0000000..827974c --- /dev/null +++ b/ejemploucha/ejemplosoto.mat @@ -0,0 +1,7 @@ +6 11 +999 18 625 416 773 0 0 0 0 0 1 +1 0 0 0 0 1 0 0 0 0 0 +0 1 0 0 0 0 1 0 0 0 0 +0 0 1 0 0 0 0 1 0 0 0 +0 0 0 1 0 0 0 0 1 0 0 +0 0 0 0 1 0 0 0 0 1 0 diff --git a/ejemploucha/ejemplosoto.zsol b/ejemploucha/ejemplosoto.zsol new file mode 100644 index 0000000..87814b9 --- /dev/null +++ b/ejemploucha/ejemplosoto.zsol @@ -0,0 +1,2 @@ +1 11 +0 0 0 0 0 1 1 1 1 1 1415 diff --git a/obj3x7.sobj b/obj3x7.sobj new file mode 100644 index 0000000000000000000000000000000000000000..936a65966a68a489043cec4edd799899d89687aa GIT binary patch literal 3469 zcmX}si9geg;{fmsxpKy)+7Ol8Q5aEFD#=lrp?y%%wPGGyB+4*SQD`CeHOKNHQu+*S zb3Bg9)%xH;ALN>NNUk2o_xt>Quix+eN4!HaXlZ^IE?#_d(m_&1IP3qVn8R@?1fO>+ z?^k}gg%)l z*lqTn;CwH#`9+v`W^=Tyq3-vB6Hb5VA<>N}d$A;l%XHe8{N1eRP&b^V*)pQ?{Q~Qk zbW-z$Bzv6onbDmpfyX>89JHT#X++)lczx%=8&|Hj`YN{QK6BLI*vQc{Se@<4o$JO0aru}ryD;o>? z&!2a7TMF`Q_PVFqI^7~m83Fxm(iZ%T=O7{EKaKCPs zoJ5^lx1`grUvh0dwEenaCtsYA*?E3nnV4rf-;CAiEc4fyX78NL0b<12ewkh|%T&IN zt7-v*mo&9sL6ebdGPOrx->G3%MU~DQa_(`yA}X;`WpAfl0whg6$QX3IByaFTC(R30 zH^!ONO0Gw(i~UaLi?Ap;Xt|`1KJ?u`fo;sz1N32(*4g3HuJ|)DryQ<689?0Ao@`e& zI$-OQr<36;txXw%$D`7}U$5e#>18ZRy3PQ|IJ~FI z^+<Y;Le- zn5JI2=!&FZ*I%@%(?4uV*bPz9tXSY?B=pXj8=*`~F@j^(*0AhvI3fqbd1E8Nh zge@F#9)ru^+0EHJE@h`ek9r7^VA7##sX|d6djc4Hka0!y!zTxxW{DzE$Z@1WXqgA*Q*rszc#?K!kkax! z>4hHTpwN;H22nGMrcoqJSCG^~d#bmHHvu-K0Y%eWN6ee1g|&=(@8dghbHJQ6ZIB3y zLTZ{D50_U`N3>5{iyu8m`qJ7#SUTosq;roUfS=b5H(e|kqJJBmy6@6=iW#2w5%uf_}Y)a7cs($p7FNTg7= z0OV6uY-{%eO%xX_sFa%0So<70!)9*-{9bz|fIsoY5y3f{<4i77K(GS{Q>8H>H0UOh zvyW7LV3`*#a3kVqfYE9=>@FOat}AoiHkDY6q9qHtzD+7^ShB;s%!&~ zGAC&@l_=a<2zF89c|!L&Jk*>YggUmJm;A-l18|*u`Do?P92L6CHQk=;k=o$~V`-lX z$!cyBQJBtZg}=F)(dej@VsZ)eqN^G^uYxeCWszjlV`PdqSy1f+Oi%Sk2;vb(>h0$8 z5(CNG;sLJk9okF|S$l-TSXr-G&2kz6oY zXlV!EXzYmS=%#(f)@)?nQ_Gb>9t)uYu$>CnuIaAqT(PV(r%<+sIRNhjv{;by@SEs2 ziKAPN7Az~usj;Wypseo2ZSxZd21!AP)VgNQ{7E1{u$TZYPp)p+klYa4I16Le2Eqxj zIW4?sS|ap*5GnF+BW3wQ~twI9N;v6Y;pPhUf?}DY>E!8sw z<`tgGJ8f~2Bx*uRqZ)BgQmNh!ptUOvm7$a&%`7o?J|5snD|97>LMA@uTKMhwDo#Dh zqc>Y6_m;2?1hLey69Y0CG8wx-tJH}?^K7VAz|00wy#|to(GzZ}3z|QS9z|Ui>VlvW zm3g98x#keb?|_j5(IUEy&5ne0y9rX(Odi3-Rb}BOA{?Pv59}0{mVlnrRiAfeHF6{x zZ!yGs@pY#SP%pfBnyA&dD=IzbgHFv3lTS_4zjyT?0}KTJmt6w~Mh86@A|A$y6|?L9 zXFDqetnbQ)P5Fqsr=VjLg;LN-`0sb~pM5x&;OuaTaYd@#h{hQJ_#$9}{ttuyT<(s_ zv{n>~&&tl`gZ09H%WIV2nkp>VhDmH4^^rW<>B5wC?W44v^aecj_nMj8gwGL-mAqB<2Ryo%oC~45s#Q4-i07kK zlaDD2^==w(&I9Z()h|KQhvjw?mUE%^H)P#=Ti#twZZl)wlJUFvnj;%IgWy_ze2<^u z^ZaQu=U^{rX?MN)x&&7u(L(Hqz8Cy-O_7Epz{XI*m1VKt&XLY^XRQY@V3p9a2wb27 z+*v!S7eC-zdze45fe-uTV^$aQbz9KYsx_hVd!aCt5LmS zQ4B0IDEZPIvQ@7B2!1CVxL3RCSvPt`cTDJXSgSY1R#>XtR}?V8ohwqI-54JoaPgo81|; z8JF@P`Hs*>AF~Sa@WtCRX#~AwRp|y9DR|8$PkQ7L# z0fvAO4dzi)8g2$sq$u`74m#N9Zp0llW+59(8hh<2LQ*8ffo<+!9#|?YJxQcBl5?u| z)u2s|Pz5K86ChzJTMbz3>e<4sPc?6>RRrP#J5KKk-eDW4u@M4AM&$vs5`Vp=( za9c3uOgvnJ;?5NIEEaXfe3nCOD9@lsfgll7_!S#@ICtMR?B{=kPeeHoR`@7KPig&J zh(8eG4RrO%4&Vlk1J(k;V{mBl?M77K66Joo8W%nwZNp)ewA$7@#%p zaARFSiuAOka+YFP_eUF1o$A7rL}=tQ(7-S@W2t?g{>vPhiP?1)1o8lU7J!19f%P%yovYU35l>g ebU$ws;(3sFo`7v*c{r>^f=JDD9 literal 0 HcmV?d00001 diff --git a/objeto.sobj b/objeto.sobj new file mode 100644 index 0000000000000000000000000000000000000000..969946b7aa77b01bbe311d403d87dc0e16035ffd GIT binary patch literal 590 zcmV-U0j?Y2?z+i_pSgDap=7Vf=B>?=|(v6MmCluuZkf+Ae0b7 z@4eT*i4^9}6TDsBoo`k;KF59OyiBQ9P_Tto^@@=r0L6-P$IWh zwknP=>sdvnNd%!ESz+W0t-Fwz9>o@}@XMA-&nB26hyB+$o>z%#rtNrL1xJy?b4r^p zM90wE$V|T>N9YZDMo$gM2HN45T|3b5g2|K8{`bL1vK-lD$WeM`urriOZzx9_a!g*1 z{TEiMg^IwZDzY(`ZqCLxjw?0hQY~>9k1zpYBElpQ-w+ydaw)Br;{8+968KciOhcHS zgyd)jnwi9B5udH%WX{l@);P^YH4kAv_ADU2koY3zi80ixpc301?@L`0Vxq zkadh2#tw#xw<2RtPCW6fCr1$I$yme&a_GzDJ~Z*g)^P4k0vQKVZHtBIfG_^^q!8(Y zfiK_xz9N&F*oKUGTb}yz$4?MXS!M}SG%CU^n{9@1k%VRrJDrVNCcI_94p*L~d2W_L zJ&VJ`IM3sx)az~DwDY`@+R?DPwP{;ij1GoX*-MRqaw0vvP~z7I4}Ww-HA?Lwjv&`& zgY<{0Dl7XQHu5q~z@|HhZI!)jQ@W*)UO5;*H+`MNHrCB5HKW`bxCSzHuG%0)Cqw?Y zQRX9CR-NH1)w3EET^h%;i=Ft=9Z-nK#`aEEG5SXdY@51K+7@BLClCo!DWYG@~%PKr?_-;l; zocUCz9HvD?LLE@0apD|3%rl#3MQYTWq`J23=9#e?TO^7|`qHXz4kKoplKBO0is|%Xoa= z`r|6IDbt5$AMdJ@)ZU0O(j?R?YE`ttJ*wjTr^kmyJV>KeY+hiSWv-vf>Kp7zsf zdcC8TDUMr)o^7>hm%7d|v<&S2z9v%wAQlGl9BPkBFk{TC^4Qp>BbZ%Vn=UWOa9acR zK<7f|K}6hL6a$_+>5khcSWiQ+d>R6(HG|-%Sir+au9{8V>1onwZDciDqC5B63hR5g zzf%@3(u%%(k@kT9(7K8R55aFl98~Cpd+&0dd!g2Z$}##F92HAQIJZM1^hS1psnK=Z zx`|<^m$>Q@fTCM>FiZ#2%iDwztUIA;>%y$^m{{PC6aui2b{;HzoCr*$+jmt74GM5W z>tTGHEis z(H*c0aG^zBLfv=F*0|^C9&b-tlA%5~Wjsf*=$d!2ptu&-+^WsCnp`h%uP%2d3%mv) zzzrJyc!Av>qE1i=d|3x?L<--(L7)iMNuV;UPZnjoC`Sv7^j>=&PIh%Z1LY#nK~@?j ze&;nBm!o>6vDz>?osF%{jUjsHL2NeqRhb?X!1^5<=0lBN2YYR1W^@gcWy8)ARFTZS znl@BzoAIa*q+82&@H(x^(=*C7Hts!-KH_sGfP+GGm1`yjJ4<>KZ=Vter$kQ)S{`W%6E*kmUy#1q(!mNZUZi($+pwOC zzvAEVzwoYlH-gXoz*|ClU-Q3m#hpBTE@H;{b&+5x*|6+Yvog&ZBHRpTR zxvm@FSWRVX8aj$iS{?thtIn>1(EHJCOc&S}u@B$Fm=+NGK4^e_SXOcMN*h?W+vZQM zh<3T4uzzbYaDieCiU{-QYfj{-o%KwtQt$q`^v$45MtS-z-y62wMX$NsoNG4lS8LXr IA2#d%1H$faBP^nZFL)pr0ZZmS*FiI}n9(C+Tj?Po( zvD`MdL+nx{#}B6qX0atr+1P218N%cByk5`qeZ4;ae*b#E-fuEJ{eAlRGjZej$!5*{ zi;LVNhTYw+r{aGoG_0iWmMs4N8ms=2crGY@?_KIcj9k3#>!ltT9C^3m-QYXl*Dj+U zO-u}T7+t%OQre~r44lX=;MF@*OsbRe?J=*T%XKTD3Ip9XW&iKh&m3lNJSBwR%1gU7 z{PF$Z$mR*J)JOJ$XozCPvsZC{;E!|St(AwPB_)*)ewtyAmXzn##Ws|7bhQshUsZPW zo99(lc~bC4MwB(d{tVr+j0q}Fy^_b<&qj-5+wBE;=< zi93ymYu#FiN_`Mn63}~=>Dkrs8{tN$MW}}T3TdBp@jdDp68XjMHu_`3$HtGDJa7Fk zb9Mzb^){iE8~W>~V~=B_SXG|KD+fLIHo7##Rbp#{+L@4)SIdXy?5b=!1V0A`f7AP> z`wgOpYRvF#bRl3PU%hkNcVH?&BS15e8eJ~^nDPm^cekvPbtmQYvEXAC<5h0kpT?{1 z&V8fmQEyU@l}lfzoC!F2_T;esy7;&1b&sCn{3hjMPrN#_hURNebn%%8q2>FoTZax z-m!8pap_sd%59*RnoHfJs!}Obzm##@A+tU3eQ*bOqQHmSne%ws=NRcnNWV_MUcYYt z(62_HF8_kNgKNdz#QiII-D6hqC2Jiz`OxWs{R8I*wpHN$yP4EgswTCF8bE#7FFk&1 zs_LtB=rX{?L&a`p0>b8FAp=Aarr(h+Sr zg`Oi+;W}^?nD($>g|5P49O2sN`*a*}2jEd{ztz;Ir2Ns6gDnq!_2!idF^^@YNYJ%jpV(K z6&e+qAsQi?BN`)`E*dUnQ;}vJeeb7cUV-5pG+L79K0P$3J)j6Yv}UI~pxmR}r*u#z zVz+pmn@=LPj+1gBoAB|ekB45C;w|}f+?%}3^`2ofbyJiNT_sq@@uocQO8X1NY+v%< zQZ21=+U+Jn^c>ye4T8$$yNJh7#`U2wm0H1&Ck1cf2wJdVWeCARf~PTUJobZ3&ZNka z7>qLQqX^)iDDrCrAK36#2tifS&DAu#s3R^C?IE6;fFZR^i$AQw?v0)_fH|**5S%br ze)C2T6ddBt3BM6FJNIC98=+y8hHH3FDPuDP50i}lfOn>k(-zq2qAX(0gwaxbzMMw1 zmBurGpv^DwH*;Kim}UY?^fVFDX)n-AgmqA+xKh@eK=hOakQbKSGEM1o&xNNIZirMS z)H0~*A{!KZkpb-Ho4p2I8O2O@wSu1}^rnP+QRd~8n7`b=Qss^O$slw$ld1jwdMnd( zdeY)}jL+v$tRcd;tr*pQoP`eUPYP%GN9NT$=9XQx#!9FxJx2Qd291|j*5*Ti;G z`X8Xv`C7e@7;zdjmhCROAd4sKV@zv`5fj-`>>~g&*`-r~q*XPiI%y3F=VW?h`yRcB zvUX2YWCO6kO7%v2;c{$yZUEJ86KY9C9h@nV6=CXz{E{qDDyRppPj(qBtc%nom=exz zrE9i^cVKcZ)JMNIKjfO&Ns1W;-Ou|%YGcHiP$b)QjHD~B6783rRhnmCLMIW#L8NK! zT7ps^y%bF}NLWeURLRxxr6PDC!YBOI6X;r|T=RV-w@ElIvrzQC6k2_^-c-pe^ySpH z$xBJOSHxb7yy85zuP9RTy^MoE)f|;-RG(O568pPK2gl52KFy!N9l;-AI8u#xv8Wrm zz)`oKv>b~=*-o&jt){;jgQ0PFbLoj8FztMZ0Y2ZI`*7l+S-}A%qxB=kf^G$>ir<1* z{=;e@v$@6;)D{;*n%@{FXttcuK|)O_rQAgRg%jvf<{PU8dz?Y19aaxH{P`gKUeOR| zPNYW+kTMN> zc?rhCJ&K=;Oq5Gc?ZNP?_&8}i4{Sf5q`l6TMn!h2qc>z1(qG*1wNwcg2J_9H0)7%` ze-<94peFQ+wk*I7M7ZUarj%L{#GXBeK+@maFJ-x=_n`#p1aMfue`)h8;CdB zQu9grm&G;=16ncLUlb)Hk~PqQ(XM*dWiumgC`1D=%Sy$d9dS8(FuFC+5Xuwo8{roj zR59`bXMzbwiwR;Z3FNJ1lT~|mL}<9ss@TUxS0vbSj^1~D##`_#zw2ipPBwp$Y}I2u zt&&ve#iSs5uFj0WSmeNkVQfpt(7aHN>vXr|)|`ZLQ91)QYUOWFHqiKR z^P*(}N~^8~wWO9&)Xn)Ivi|ex7W%DGK?E^LDyau@CMOLRHbkoPmL+mO8IG)j*=5~7 zl8Vx@MZtfotM^Fr@E;IPw#ZP0;cI1PYBJWVQ2mPEh7*JQ|ZgvHtc~%sJXlYukgF*!2agmoj?Pz*F1u^*#>76jPopnWikgclax3H zK9dM&%hGuPMGnZ2WUuNKT(jx4_ENC{Tf0qONwSU=8!`|9VmCUXIE3ve3XS(Ex$(8&JNMgyI(KAsS-iLjK-)+C^ZbI`YecT!0lFT3%^lg(@kv3z+ z2#m!@02;vEEnP(Mki=|LLA6Rjp`{(y#x0(dTz!D(h3J&R!XnCrk0cFj8gyf zECxn533ha8+hVcXtej23C@h|wl&uwwU&k3SRn}ce*T??0(jytbwQqQOY4T4r!5tqpF6t} zbUUcwyaZu;_9-+pTc|Mq+E8Z&|606U-t0Sr$fsy7YG`x)h^_)NeUWCJx%ofqM9?xe z^LDdwJLeS9W9cTx#$=KEYa=|ZpgWFW0Fw@mMx0-Qtx(pv8^TSQiURrqw?n(Y4X$SJ zZZyjLFul&U*=MJRT#Caw=OgdlM@7E89v0I~tDV0Hea~6&Oe>%zUY>Vg zB+)w9;i3ec59M+zSunXOE$c;2i$#IAEJ7-H0<2GFsw`-a5ld=$Q3tFj72E;gtV~yF zm#ydX48XJGj5NLx7`1`PrquERph(XD5@*$`I`b9`=Vw*}8O^z-y#wGn9Fvdus4Xk$ atE*`Fw??j>Z$WL`JOuq=Q#%J(O8XCTw^O+Q literal 0 HcmV?d00001 diff --git a/temporary_file__.cost b/temporary_file__.cost new file mode 100644 index 0000000..740fd72 --- /dev/null +++ b/temporary_file__.cost @@ -0,0 +1,2 @@ +1 28 +-4 -1 -1 -3 -4 -2 -2 -2 -2 -3 -1 -3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 diff --git a/temporary_file__.gro b/temporary_file__.gro new file mode 100644 index 0000000..f24f7d6 --- /dev/null +++ b/temporary_file__.gro @@ -0,0 +1,67 @@ +66 28 +-1 0 0 0 0 -1 0 0 0 1 0 1 0 0 -1 1 1 0 0 0 0 1 0 0 0 -1 0 -1 +-1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 3 1 0 0 0 0 0 0 0 0 0 0 0 +-1 0 0 0 0 0 0 0 0 0 0 1 -2 -2 -3 2 1 0 0 0 0 0 0 0 0 0 0 -1 +-1 0 0 0 0 0 0 0 0 0 1 0 -2 -1 -3 0 1 0 0 0 0 0 0 0 0 0 -1 0 +-1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 -1 0 0 +-1 0 0 0 0 0 0 1 0 0 0 0 -1 -2 -1 2 1 0 0 0 0 0 0 -1 0 0 0 0 +-1 0 0 0 0 0 1 0 0 0 0 0 -2 -2 0 2 1 0 0 0 0 0 -1 0 0 0 0 0 +-1 0 0 0 0 1 0 0 0 0 0 0 -2 -2 -2 3 1 0 0 0 0 -1 0 0 0 0 0 0 +-1 0 0 1 0 -1 0 0 0 0 0 1 -2 0 -3 0 1 0 0 -1 0 1 0 0 0 0 0 -1 +-1 0 0 1 0 -1 0 0 0 1 0 0 0 2 0 0 1 0 0 -1 0 1 0 0 0 -1 0 0 +-1 0 0 1 0 -1 0 1 0 0 0 0 -1 0 -1 0 1 0 0 -1 0 1 0 -1 0 0 0 0 +-1 0 0 1 0 -1 1 0 0 0 0 0 -2 0 0 0 1 0 0 -1 0 1 -1 0 0 0 0 0 +-1 0 0 1 0 0 0 0 0 0 0 0 -2 0 -2 1 1 0 0 -1 0 0 0 0 0 0 0 0 +-1 0 1 0 0 0 0 0 0 0 0 0 1 -2 -2 2 1 0 -1 0 0 0 0 0 0 0 0 0 +-1 0 1 0 0 0 0 0 0 1 0 0 0 -2 -2 1 1 0 -1 0 0 0 0 0 0 -1 0 0 +-1 0 1 1 0 0 0 0 0 0 0 0 -2 -2 -4 0 1 0 -1 -1 0 0 0 0 0 0 0 0 + 0 0 -1 0 0 0 0 0 0 0 0 0 0 2 2 1 0 0 1 0 0 0 0 0 0 0 0 0 + 0 0 -1 0 0 0 0 0 0 0 1 0 -3 1 -1 -2 0 0 1 0 0 0 0 0 0 0 -1 0 + 0 0 -1 1 0 0 0 0 0 -1 0 0 -2 2 0 0 0 0 1 -1 0 0 0 0 0 1 0 0 + 0 0 0 -1 0 0 0 0 0 0 0 0 3 0 2 2 0 0 0 1 0 0 0 0 0 0 0 0 + 0 0 0 -1 0 0 0 0 0 0 0 1 0 -2 -1 1 0 0 0 1 0 0 0 0 0 0 0 -1 + 0 0 0 -1 0 0 0 0 0 0 1 0 0 -1 -1 -1 0 0 0 1 0 0 0 0 0 0 -1 0 + 0 0 0 -1 0 0 0 0 0 1 0 0 2 0 2 1 0 0 0 1 0 0 0 0 0 -1 0 0 + 0 0 0 -1 0 0 0 1 0 0 0 0 1 -2 1 1 0 0 0 1 0 0 0 -1 0 0 0 0 + 0 0 0 -1 0 0 1 0 0 0 0 0 0 -2 2 1 0 0 0 1 0 0 -1 0 0 0 0 0 + 0 0 0 -1 0 1 0 0 0 0 0 0 0 -2 0 2 0 0 0 1 0 -1 0 0 0 0 0 0 + 0 0 0 0 0 -1 0 0 0 0 0 0 3 2 2 0 0 0 0 0 0 1 0 0 0 0 0 0 + 0 0 0 0 0 -1 0 0 0 0 1 0 0 1 -1 -3 0 0 0 0 0 1 0 0 0 0 -1 0 + 0 0 0 0 0 -1 0 1 0 0 0 0 1 0 1 -1 0 0 0 0 0 1 0 -1 0 0 0 0 + 0 0 0 0 0 -1 1 0 0 0 0 0 0 0 2 -1 0 0 0 0 0 1 -1 0 0 0 0 0 + 0 0 0 0 0 0 -1 0 0 0 0 0 3 2 0 1 0 0 0 0 0 0 1 0 0 0 0 0 + 0 0 0 0 0 0 -1 0 0 0 1 0 0 1 -3 -2 0 0 0 0 0 0 1 0 0 0 -1 0 + 0 0 0 0 0 0 -1 1 0 0 0 0 1 0 -1 0 0 0 0 0 0 0 1 -1 0 0 0 0 + 0 0 0 0 0 0 0 -1 0 0 0 0 2 2 1 1 0 0 0 0 0 0 0 1 0 0 0 0 + 0 0 0 0 0 0 0 -1 0 0 1 0 -1 1 -2 -2 0 0 0 0 0 0 0 1 0 0 -1 0 + 0 0 0 0 0 0 0 0 0 -1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 + 0 0 0 0 0 0 0 0 0 -1 0 1 -2 -2 -3 0 0 0 0 0 0 0 0 0 0 1 0 -1 + 0 0 0 0 0 0 0 0 0 -1 1 0 -2 -1 -3 -2 0 0 0 0 0 0 0 0 0 1 -1 0 + 0 0 0 0 0 0 0 0 0 0 -1 0 3 1 3 3 0 0 0 0 0 0 0 0 0 0 1 0 + 0 0 0 0 0 0 0 0 0 0 0 -1 3 2 3 1 0 0 0 0 0 0 0 0 0 0 0 1 + 0 0 0 0 0 0 0 0 0 0 1 -1 0 1 0 -2 0 0 0 0 0 0 0 0 0 0 -1 1 + 0 0 0 0 0 0 0 1 0 -1 0 0 -1 -2 -1 0 0 0 0 0 0 0 0 -1 0 1 0 0 + 0 0 0 0 0 0 0 1 0 0 0 -1 1 0 2 0 0 0 0 0 0 0 0 -1 0 0 0 1 + 0 0 0 0 0 0 1 0 0 -1 0 0 -2 -2 0 0 0 0 0 0 0 0 -1 0 0 1 0 0 + 0 0 0 0 0 0 1 0 0 0 0 -1 0 0 3 0 0 0 0 0 0 0 -1 0 0 0 0 1 + 0 0 0 0 0 1 0 0 0 -1 0 0 -2 -2 -2 1 0 0 0 0 0 -1 0 0 0 1 0 0 + 0 0 0 0 0 1 0 0 0 0 0 -1 0 0 1 1 0 0 0 0 0 -1 0 0 0 0 0 1 + 0 0 0 1 0 -1 0 0 0 -1 0 0 1 2 0 -1 0 0 0 -1 0 1 0 0 0 1 0 0 + 0 0 0 1 0 0 -1 0 0 -1 0 0 1 2 -2 0 0 0 0 -1 0 0 1 0 0 1 0 0 + 0 0 0 1 0 0 0 -1 0 -1 0 0 0 2 -1 0 0 0 0 -1 0 0 0 1 0 1 0 0 + 0 0 0 1 0 0 0 0 0 -1 0 -1 1 2 1 0 0 0 0 -1 0 0 0 0 0 1 0 1 + 0 0 0 1 0 1 0 0 0 -1 0 -1 -2 0 -1 0 0 0 0 -1 0 -1 0 0 0 1 0 1 + 0 0 1 -1 0 0 0 0 0 0 0 0 3 -2 0 1 0 0 -1 1 0 0 0 0 0 0 0 0 + 0 0 1 0 0 -1 0 0 0 0 0 0 3 0 0 -1 0 0 -1 0 0 1 0 0 0 0 0 0 + 0 0 1 0 0 0 -1 0 0 0 0 0 3 0 -2 0 0 0 -1 0 0 0 1 0 0 0 0 0 + 0 0 1 0 0 0 0 -1 0 0 0 0 2 0 -1 0 0 0 -1 0 0 0 0 1 0 0 0 0 + 0 0 1 0 0 0 0 0 0 -1 0 0 1 -2 -2 0 0 0 -1 0 0 0 0 0 0 1 0 0 + 0 0 1 0 0 0 0 0 0 0 0 -1 3 0 1 0 0 0 -1 0 0 0 0 0 0 0 0 1 + 0 0 1 1 0 0 0 -1 0 -1 0 0 0 0 -3 -1 0 0 -1 -1 0 0 0 1 0 1 0 0 + 1 0 0 -1 0 0 -1 0 0 0 0 0 5 2 2 0 -1 0 0 1 0 0 1 0 0 0 0 0 + 1 0 0 -1 0 0 0 -1 0 0 0 0 4 2 3 0 -1 0 0 1 0 0 0 1 0 0 0 0 + 1 0 0 -1 0 0 0 0 0 -1 0 0 3 0 2 0 -1 0 0 1 0 0 0 0 0 1 0 0 + 1 0 0 -1 0 0 0 0 0 0 0 -1 5 2 5 0 -1 0 0 1 0 0 0 0 0 0 0 1 + 1 0 0 0 0 0 -1 0 0 -1 0 0 3 2 0 -1 -1 0 0 0 0 0 1 0 0 1 0 0 + 1 0 0 0 0 0 0 -1 0 -1 0 0 2 2 1 -1 -1 0 0 0 0 0 0 1 0 1 0 0 + 1 0 0 0 0 0 0 0 0 -1 0 -1 3 2 3 -1 -1 0 0 0 0 0 0 0 0 1 0 1 diff --git a/temporary_file__.mat b/temporary_file__.mat new file mode 100644 index 0000000..2bc07d2 --- /dev/null +++ b/temporary_file__.mat @@ -0,0 +1,17 @@ +16 28 +1 0 0 3 1 3 3 2 1 1 3 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 3 2 0 3 2 2 2 3 0 1 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 1 2 2 1 2 0 1 2 0 3 3 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 +3 0 1 2 0 0 1 1 0 1 3 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 +1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 +0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 +0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 +0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 +0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 +0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 +0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 +0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 +0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 +0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 diff --git a/temporary_file__.zsol b/temporary_file__.zsol new file mode 100644 index 0000000..73bf237 --- /dev/null +++ b/temporary_file__.zsol @@ -0,0 +1,2 @@ +1 28 +0 0 0 0 0 0 0 0 0 0 0 0 17 2 13 9 1 1 1 1 1 1 1 1 1 1 1 1 diff --git a/truncated.ipynb b/truncated.ipynb index 3b71f6e..8c5af24 100644 --- a/truncated.ipynb +++ b/truncated.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 297, + "execution_count": 28, "metadata": { "collapsed": false }, @@ -14,13 +14,13 @@ "def random_lll(l,n):\n", " return [ [ZZ.random_element() for i in xrange(l)] for j in xrange(n)]\n", "\n", - "longitud = 500\n", - "numero = 100\n", + "longitud = 50\n", + "numero = 100000\n", "\n", - "xxx = random_lll(longitud, numero)\n", - "yyy = random_lll(longitud, numero)\n", - "zzz = [vector(ZZ,z) for z in xxx]\n", - "ttt = [vector(ZZ,z) for z in yyy]\n", + "#xxx = random_lll(longitud, numero)\n", + "#yyy = random_lll(longitud, numero)\n", + "#zzz = [vector(ZZ,z) for z in xxx]\n", + "#ttt = [vector(ZZ,z) for z in yyy]\n", "\n", "#vvv = random_vvv(5000, 1000)\n", "#yyy = random_vvv(5000, 1000)" @@ -28,19 +28,72 @@ }, { "cell_type": "code", - "execution_count": 401, + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 159, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Primer ejemplo" + ] + }, + { + "cell_type": "code", + "execution_count": 264, "metadata": { "collapsed": false }, "outputs": [], "source": [ "reset()\n", + "load(\"resolutor.py\")\n", "load(\"truncated.py\")" ] }, { "cell_type": "code", - "execution_count": 402, + "execution_count": 265, "metadata": { "collapsed": false }, @@ -57,7 +110,7 @@ ")" ] }, - "execution_count": 402, + "execution_count": 265, "metadata": {}, "output_type": "execute_result" } @@ -68,7 +121,7 @@ }, { "cell_type": "code", - "execution_count": 403, + "execution_count": 267, "metadata": { "collapsed": false, "scrolled": true @@ -78,17 +131,20 @@ "name": "stdout", "output_type": "stream", "text": [ - "3496 criterion 1, 689 criterion 2, 5774 criterion 3, 83 non eligible, 14 equalities, 384 reductions, of which 246 to zero\n" + "4588 criterion 1, 1421 criterion 2, 8437 criterion 3, 64 non feasible, 541 reductions, of which 374 to zero\n", + " " ] } ], "source": [ - "vecs, g = bubu(A1,b1,c1,vector(ZZ, 7*[1]))\n" + "%%prun\n", + "\n", + "vecs, g = bubu(A1,b1,c1,vector(ZZ, 7*[38]))\n" ] }, { "cell_type": "code", - "execution_count": 404, + "execution_count": 183, "metadata": { "collapsed": false }, @@ -96,10 +152,10 @@ { "data": { "text/plain": [ - "145" + "174" ] }, - "execution_count": 404, + "execution_count": 183, "metadata": {}, "output_type": "execute_result" } @@ -110,18 +166,76 @@ }, { "cell_type": "code", - "execution_count": 405, + "execution_count": 184, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "GG = bigsolve(A1,b1,c1,u1)" + ] + }, + { + "cell_type": "code", + "execution_count": 185, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "63" + ] + }, + "execution_count": 185, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(GG)" + ] + }, + { + "cell_type": "code", + "execution_count": 186, "metadata": { "collapsed": false }, "outputs": [], + "source": [ + "for v in GG:\n", + " if not (v in vecs or -v in vecs): \n", + " print copy(v), g.reduce(copy(v))" + ] + }, + { + "cell_type": "code", + "execution_count": 187, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'PartialBasis' object has no attribute 'self_reduce'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/Applications/SageMath-7.5.1.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/all_cmdline.pyc\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mself_reduce\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m: 'PartialBasis' object has no attribute 'self_reduce'" + ] + } + ], "source": [ "g.self_reduce()" ] }, { "cell_type": "code", - "execution_count": 406, + "execution_count": 188, "metadata": { "collapsed": false }, @@ -129,10 +243,10 @@ { "data": { "text/plain": [ - "114" + "174" ] }, - "execution_count": 406, + "execution_count": 188, "metadata": {}, "output_type": "execute_result" } @@ -141,6 +255,19 @@ "len(g.vectors)" ] }, + { + "cell_type": "code", + "execution_count": 189, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "for v in GG:\n", + " if not (v in vecs or -v in vecs): \n", + " print copy(v), g.reduce(copy(v))" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -150,7 +277,7 @@ }, { "cell_type": "code", - "execution_count": 407, + "execution_count": 238, "metadata": { "collapsed": false }, @@ -159,12 +286,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "133 criterion 1, 10 criterion 2, 99 criterion 3, 0 non eligible, 0 equalities, 34 reductions, of which 15 to zero\n" + "74 criterion 1, 9 criterion 2, 72 criterion 3, 10 non feasible, 25 reductions, of which 10 to zero\n" ] } ], "source": [ - "reset()\n", + "load(\"resolutor.py\")\n", "load(\"truncated.py\")\n", "A = matrix(ZZ,[[999, 18, 625, 416, 773]])\n", "b = vector(ZZ, [1415])\n", @@ -176,7 +303,7 @@ }, { "cell_type": "code", - "execution_count": 408, + "execution_count": 239, "metadata": { "collapsed": false }, @@ -190,27 +317,23 @@ " (0, 0, 0, 1, 0),\n", " (0, 0, 0, 0, 1),\n", " (0, 0, 0, -1, 1),\n", - " (0, 0, 0, -2, 1),\n", " (0, 0, 1, 1, -1),\n", - " (0, 0, 1, 0, -1),\n", - " (0, 1, 0, -1, 0),\n", - " (-1, 0, 1, 0, 0),\n", + " (0, 1, -1, -1, 1),\n", " (0, 1, 0, 1, -1),\n", " (-1, 0, 0, 0, 1),\n", + " (0, 0, 1, 0, -1),\n", " (0, -1, 0, 0, 1),\n", - " (0, 2, 0, 0, -1),\n", " (0, 0, 1, -1, 0),\n", - " (0, 0, 1, -2, 0),\n", " (0, -1, 1, -1, 0),\n", + " (-1, 0, 1, 0, 0),\n", + " (0, 1, 0, -1, 0),\n", " (1, 0, 0, -1, 0),\n", - " (-1, 0, 0, 2, 0),\n", " (-1, 1, 0, 1, 0),\n", " (0, -1, 1, 0, 0),\n", - " (0, 2, -1, 0, 0),\n", " (-1, 1, 0, 0, 0)]" ] }, - "execution_count": 408, + "execution_count": 239, "metadata": {}, "output_type": "execute_result" } @@ -221,7 +344,7 @@ }, { "cell_type": "code", - "execution_count": 409, + "execution_count": 240, "metadata": { "collapsed": false }, @@ -229,10 +352,10 @@ { "data": { "text/plain": [ - "24" + "20" ] }, - "execution_count": 409, + "execution_count": 240, "metadata": {}, "output_type": "execute_result" } @@ -243,7 +366,7 @@ }, { "cell_type": "code", - "execution_count": 410, + "execution_count": 241, "metadata": { "collapsed": false }, @@ -251,62 +374,60 @@ { "data": { "text/plain": [ - "22" + "17" ] }, - "execution_count": 410, + "execution_count": 241, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "GG=load('objeto')\n", + "GG = bigsolve(A,b,c,u)\n", "len(GG)" ] }, { "cell_type": "code", - "execution_count": 411, + "execution_count": 243, "metadata": { "collapsed": false }, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "[-1 0 0 0 0]\n", - "[-1 0 0 1 0]\n", - "[ 0 -2 0 0 1]\n", - "[ 0 -2 1 0 0]\n", - "[ 0 -1 0 -1 1]\n", - "[ 0 -1 0 0 0]\n", - "[ 0 -1 0 1 0]\n", - "[ 0 0 -1 0 0]\n", - "[ 0 0 -1 0 1]\n", - "[ 0 0 -1 1 0]\n", - "[ 0 0 -1 2 0]\n", - "[ 0 0 0 -1 0]\n", - "[ 0 0 0 0 -1]\n", - "[ 0 0 0 1 -1]\n", - "[ 0 0 0 2 -1]\n", - "[ 0 1 -1 0 0]\n", - "[ 0 1 -1 1 0]\n", - "[ 0 1 0 0 -1]\n", - "[ 1 -1 0 0 0]\n", - "[ 1 0 -1 0 0]\n", - "[ 1 0 0 -2 0]\n", - "[ 1 0 0 0 -1]\n" - ] + "data": { + "text/plain": [ + "[(-1, 0, 0, 0, 0),\n", + " (-1, 0, 0, 1, 0),\n", + " (0, -1, 0, -1, 1),\n", + " (0, -1, 0, 0, 0),\n", + " (0, -1, 0, 1, 0),\n", + " (0, 0, -1, 0, 0),\n", + " (0, 0, -1, 0, 1),\n", + " (0, 0, -1, 1, 0),\n", + " (0, 0, 0, -1, 0),\n", + " (0, 0, 0, 0, -1),\n", + " (0, 0, 0, 1, -1),\n", + " (0, 1, -1, 0, 0),\n", + " (0, 1, -1, 1, 0),\n", + " (0, 1, 0, 0, -1),\n", + " (1, -1, 0, 0, 0),\n", + " (1, 0, -1, 0, 0),\n", + " (1, 0, 0, 0, -1)]" + ] + }, + "execution_count": 243, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "print matrix(GG).str()\n" + " GG\n" ] }, { "cell_type": "code", - "execution_count": 412, + "execution_count": 244, "metadata": { "collapsed": false }, @@ -316,7 +437,8 @@ "output_type": "stream", "text": [ "(-1, 1, 0, 1, 0)\n", - "(0, 0, 1, 1, -1)\n" + "(0, 0, 1, 1, -1)\n", + "(0, 1, -1, -1, 1)\n" ] } ], @@ -327,7 +449,7 @@ }, { "cell_type": "code", - "execution_count": 413, + "execution_count": 245, "metadata": { "collapsed": false }, @@ -339,20 +461,21 @@ }, { "cell_type": "code", - "execution_count": 414, + "execution_count": 198, "metadata": { "collapsed": false }, "outputs": [ { - "data": { - "text/plain": [ - "22" - ] - }, - "execution_count": 414, - "metadata": {}, - "output_type": "execute_result" + "ename": "AttributeError", + "evalue": "'PartialBasis' object has no attribute 'self_reduce'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/Applications/SageMath-7.5.1.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/all_cmdline.pyc\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mself_reduce\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvectors\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mAttributeError\u001b[0m: 'PartialBasis' object has no attribute 'self_reduce'" + ] } ], "source": [ @@ -362,7 +485,7 @@ }, { "cell_type": "code", - "execution_count": 415, + "execution_count": 199, "metadata": { "collapsed": false }, @@ -384,19 +507,19 @@ }, { "cell_type": "code", - "execution_count": 400, + "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ - "reset()\n", + "load(\"resolutor.py\")\n", "load(\"truncated.py\")" ] }, { "cell_type": "code", - "execution_count": 325, + "execution_count": 2, "metadata": { "collapsed": false }, @@ -405,7 +528,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "2442 criterion 1, 447 criterion 2, 3734 criterion 3, 108 non eligible, 10 equalities, 280 reductions, of which 168 to zero\n" + "265 criterion 1, 87 criterion 2, 536 criterion 3, 126 non feasible, 67 reductions, of which 27 to zero\n" ] } ], @@ -421,7 +544,7 @@ }, { "cell_type": "code", - "execution_count": 326, + "execution_count": 3, "metadata": { "collapsed": false }, @@ -429,10 +552,10 @@ { "data": { "text/plain": [ - "119" + "47" ] }, - "execution_count": 326, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -441,35 +564,88 @@ "len(vects)" ] }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "RuntimeError", + "evalue": "ha fallado 4ti2", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mgg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mbigsolve\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mA1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mc1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mu1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Users/soto/Documents/Maths/Papers/optimizacion/gsu/resolutor.py\u001b[0m in \u001b[0;36mbigsolve\u001b[0;34m(A, b, c, u)\u001b[0m\n\u001b[1;32m 61\u001b[0m \u001b[0;34m\".cost\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mmatrix_to_42\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mmatrix\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbigc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 62\u001b[0m }\n\u001b[0;32m---> 63\u001b[0;31m \u001b[0mGG\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmatrix\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mZZ\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mrun_4ti2\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"../42/pruebas/groebner -t lp\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m\".gro\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 64\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mGG\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrows\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 65\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/Users/soto/Documents/Maths/Papers/optimizacion/gsu/resolutor.py\u001b[0m in \u001b[0;36mrun_4ti2\u001b[0;34m(command, data, results)\u001b[0m\n\u001b[1;32m 11\u001b[0m )\n\u001b[1;32m 12\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 13\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mRuntimeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"ha fallado 4ti2\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 14\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mload_42_matrix\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mr\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mresults\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mRuntimeError\u001b[0m: ha fallado 4ti2" + ] + } + ], + "source": [ + "gg = bigsolve(A1,b1,c1,u1)\n", + "len(gg)" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": { - "collapsed": true + "collapsed": false }, "outputs": [], "source": [] }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# Ejemplo duro de roer" + ] + }, { "cell_type": "code", - "execution_count": 327, + "execution_count": 47, "metadata": { "collapsed": false }, "outputs": [], "source": [ - "reset()\n", + "\n", "load(\"truncated.py\")" ] }, { "cell_type": "code", - "execution_count": 328, + "execution_count": 48, "metadata": { "collapsed": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1648 criterion 1, 833 criterion 2, 1973 criterion 3, 513 non feasible, 184 reductions, of which 94 to zero\n", + "1648 criterion 1, 833 criterion 2, 1973 criterion 3, 513 non feasible, 184 reductions, of which 94 to zero\n", + "1648 criterion 1, 833 criterion 2, 1973 criterion 3, 513 non feasible, 184 reductions, of which 94 to zero\n", + "1648 criterion 1, 833 criterion 2, 1973 criterion 3, 513 non feasible, 184 reductions, of which 94 to zero\n", + "1648 criterion 1, 833 criterion 2, 1973 criterion 3, 513 non feasible, 184 reductions, of which 94 to zero\n", + "1648 criterion 1, 833 criterion 2, 1973 criterion 3, 513 non feasible, 184 reductions, of which 94 to zero\n", + "1648 criterion 1, 833 criterion 2, 1973 criterion 3, 513 non feasible, 184 reductions, of which 94 to zero\n", + "1648 criterion 1, 833 criterion 2, 1973 criterion 3, 513 non feasible, 184 reductions, of which 94 to zero\n", + "1648 criterion 1, 833 criterion 2, 1973 criterion 3, 513 non feasible, 184 reductions, of which 94 to zero\n", + "3 loops, best of 3: 449 ms per loop\n" + ] + } + ], "source": [ + "%%timeit -r3 -n3\n", "c1=vector(ZZ,(4, 1, 1, 3, 4, 2, 2, 2, 2, 3, 1, 3))\n", "A1=matrix(ZZ, [[1, 0, 0, 3, 1, 3, 3, 2, 1, 1, 3, 3],\n", " [0, 3, 2, 0, 3, 2, 2, 2, 3, 0, 1, 2],\n", @@ -477,60 +653,179 @@ " [3, 0, 1, 2, 0, 0, 1, 1, 0, 1, 3, 1]])\n", "b1=vector(ZZ,(17, 2, 13, 9))\n", "u1=vector(ZZ,(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1))\n", - "#v, g = bubu(A1,b1,c1,u1)\n", - "\n" + "v, g = bubu(A1,b1,c1,u1)\n" ] }, { "cell_type": "code", - "execution_count": 329, + "execution_count": 8, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ "reset()\n", "load(\"truncated.py\")\n", - "#v, g = bubu(B,b2,c2,u2)\n" + "load(\"resolutor.py\")" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": 11, "metadata": { - "collapsed": true + "collapsed": false, + "scrolled": true }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1648 criterion 1, 833 criterion 2, 1973 criterion 3, 513 non feasible, 184 reductions, of which 94 to zero\n", + " " + ] + } + ], "source": [ - "## Ejemplo de Ucha" + "%%prun\n", + "c1=vector(ZZ,(4, 1, 1, 3, 4, 2, 2, 2, 2, 3, 1, 3))\n", + "A1=matrix(ZZ, [[1, 0, 0, 3, 1, 3, 3, 2, 1, 1, 3, 3],\n", + " [0, 3, 2, 0, 3, 2, 2, 2, 3, 0, 1, 2],\n", + " [0, 1, 2, 2, 1, 2, 0, 1, 2, 0, 3, 3],\n", + " [3, 0, 1, 2, 0, 0, 1, 1, 0, 1, 3, 1]])\n", + "b1=vector(ZZ,(17, 2, 13, 9))\n", + "u1=vector(ZZ,(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1))\n", + "v, g = bubu(A1,b1,c1,u1)\n", + "\n", + "\n" ] }, { "cell_type": "code", - "execution_count": 347, + "execution_count": 621, "metadata": { "collapsed": false }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, -1),\n", + " (0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 1),\n", + " (0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, -1),\n", + " (0, 0, 0, -1, 0, 0, 0, -1, 0, 1, 0, 1),\n", + " (1, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1),\n", + " (-1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0),\n", + " (1, 0, 0, -1, 0, 1, 0, -1, 0, 0, 0, 0),\n", + " (1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1),\n", + " (0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1),\n", + " (0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, -1),\n", + " (0, 0, 0, -1, 0, 0, -1, 0, 0, 1, 0, 1),\n", + " (1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 0, 1),\n", + " (-1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0),\n", + " (1, 0, 0, -1, 0, 1, -1, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1),\n", + " (0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, -1),\n", + " (0, 0, 0, -1, 0, -1, 0, 0, 0, 1, 0, 1),\n", + " (1, 0, 0, -1, 0, -1, 0, 0, 0, 0, 0, 1),\n", + " (1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (1, 0, 0, -1, 0, 1, 0, 0, 0, 0, 0, -1),\n", + " (-1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1),\n", + " (-1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0),\n", + " (1, 0, 0, -1, 0, 1, 0, 0, 0, -1, 0, 0),\n", + " (-1, 0, 1, 1, 0, -1, 0, 0, 0, 1, 0, 0),\n", + " (1, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1),\n", + " (1, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, -1),\n", + " (0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1),\n", + " (0, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1),\n", + " (0, 0, -1, 0, 0, 0, 0, 0, 0, 1, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0),\n", + " (0, 0, 0, -1, 0, 0, 0, 1, 0, 1, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, 1, -1, 0, -1, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, -1, 1, 0, 1, 0, 0),\n", + " (-1, 0, 0, 1, 0, 0, -1, 1, 0, 1, 0, 0),\n", + " (0, 0, 0, 1, 0, 1, 0, -1, 0, -1, 0, 0),\n", + " (0, 0, -1, -1, 0, 0, 0, 1, 0, 1, 0, 0),\n", + " (0, 0, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, -1, 1, 0, -1, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, -1, 1, 0, 0, 0, 0),\n", + " (1, 0, 0, 0, 0, 0, -1, 1, 0, 0, 0, 0),\n", + " (0, 0, 0, 1, 0, 1, -1, 0, 0, -1, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, -1, 0, 1, 0, 0, 0, 1, 0, 0),\n", + " (0, 0, 0, 1, 0, -1, 0, 1, 0, -1, 0, 0),\n", + " (0, 0, 0, 1, 0, -1, 1, 0, 0, -1, 0, 0),\n", + " (0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, 1, -1, 0, 0, 0, 0, 0, 1, 0, 0),\n", + " (0, 0, -1, 1, 0, 0, 0, 1, 0, -1, 0, 0),\n", + " (0, 0, 1, 0, 0, 0, 0, -1, 0, 1, 0, 0),\n", + " (0, 0, -1, 1, 0, 0, 1, 0, 0, -1, 0, 0),\n", + " (0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, 0),\n", + " (0, 0, -1, 1, 0, 1, 0, 0, 0, -1, 0, 0),\n", + " (1, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0),\n", + " (-1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1),\n", + " (-1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0),\n", + " (1, 0, 0, 0, 0, 1, 0, -1, 0, -1, 0, 0),\n", + " (-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0),\n", + " (1, 0, 0, 0, 0, 1, -1, 0, 0, -1, 0, 0),\n", + " (1, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0),\n", + " (0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 1),\n", + " (1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1),\n", + " (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0),\n", + " (0, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0),\n", + " (0, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0),\n", + " (0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0),\n", + " (0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0),\n", + " (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, -1, 0, 1, 0, 0),\n", + " (0, 0, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0),\n", + " (0, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0),\n", + " (1, 0, 0, 0, 0, -1, 0, 1, 0, 0, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0),\n", + " (0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0),\n", + " (1, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0),\n", + " (1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0),\n", + " (0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0),\n", + " (1, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, 0),\n", + " (1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0),\n", + " (0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0),\n", + " (1, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0),\n", + " (1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0)]" + ] + }, + "execution_count": 621, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "def load_42_matrix(fname):\n", - " \"\"\"docstring for load_42_matrix\"\"\"\n", - " with open(fname) as f:\n", - " s=f.read().splitlines()\n", - " return [line_to_list(l) for l in s[1:]]\n", - "def line_to_list(s):\n", - " \"\"\"docstring for line_to_list\"\"\"\n", - " return [Integer(i) for i in s.strip().split()]\n", - "\n", - "Ap = matrix(matrix(ZZ, load_42_matrix(\"ejemploucha/ejemplosoto.mat\"))[0][:5])\n", - "cp = -vector(ZZ, load_42_matrix(\"ejemploucha/ejemplosoto.cost\")[0])[:5]\n", - "zsol = vector(ZZ,load_42_matrix(\"ejemploucha/ejemplosoto.zsol\")[0])\n", - "\n", - "b = vector(ZZ,[1415])\n", - "u = vector(ZZ, 5*[1])" + "g.vectors" ] }, { "cell_type": "code", - "execution_count": 348, + "execution_count": 622, "metadata": { "collapsed": false }, @@ -538,22 +833,32 @@ { "data": { "text/plain": [ - "(252, 537, 965, 237, 724, 0, 0, 0, 0, 0, 0)" + "102" ] }, - "execution_count": 348, + "execution_count": 622, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "\n", - "-vector(ZZ, load_42_matrix(\"ejemploucha/ejemplosoto.cost\")[0])" + "len(g.vectors)" ] }, { "cell_type": "code", - "execution_count": 349, + "execution_count": 623, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "g.self_reduce()" + ] + }, + { + "cell_type": "code", + "execution_count": 624, "metadata": { "collapsed": false }, @@ -561,27 +866,21 @@ { "data": { "text/plain": [ - "[999 18 625 416 773 0 0 0 0 0 1]\n", - "[ 1 0 0 0 0 1 0 0 0 0 0]\n", - "[ 0 1 0 0 0 0 1 0 0 0 0]\n", - "[ 0 0 1 0 0 0 0 1 0 0 0]\n", - "[ 0 0 0 1 0 0 0 0 1 0 0]\n", - "[ 0 0 0 0 1 0 0 0 0 1 0]" + "69" ] }, - "execution_count": 349, + "execution_count": 624, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "AAA = matrix(ZZ, load_42_matrix(\"ejemploucha/ejemplosoto.mat\"))\n", - "AAA" + "len(g.vectors)" ] }, { "cell_type": "code", - "execution_count": 350, + "execution_count": 625, "metadata": { "collapsed": false }, @@ -589,21 +888,22 @@ { "data": { "text/plain": [ - "(1415, 1, 1, 1, 1, 1)" + "66" ] }, - "execution_count": 350, + "execution_count": 625, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "AAA*zsol" + "GG = bigsolve(A1,b1,c1,u1)\n", + "len(GG)" ] }, { "cell_type": "code", - "execution_count": 351, + "execution_count": 626, "metadata": { "collapsed": false }, @@ -611,73 +911,151 @@ { "data": { "text/plain": [ - "([999 18 625 416 773],\n", - " (252, 537, 965, 237, 724),\n", - " (0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1415))" + "[(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, -1),\n", + " (0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 1),\n", + " (-1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0),\n", + " (1, 0, 0, -1, 0, 1, 0, -1, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1),\n", + " (-1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0),\n", + " (1, 0, 0, -1, 0, 1, -1, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1),\n", + " (0, 0, 0, -1, 0, -1, 0, 0, 0, 1, 0, 1),\n", + " (1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (1, 0, 0, -1, 0, 1, 0, 0, 0, 0, 0, -1),\n", + " (-1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1),\n", + " (-1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0),\n", + " (1, 0, 0, -1, 0, 1, 0, 0, 0, -1, 0, 0),\n", + " (1, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (1, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, -1),\n", + " (0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1),\n", + " (0, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1),\n", + " (0, 0, -1, 0, 0, 0, 0, 0, 0, 1, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0),\n", + " (0, 0, 0, -1, 0, 0, 0, 1, 0, 1, 0, 0),\n", + " (0, 0, -1, -1, 0, 0, 0, 1, 0, 1, 0, 0),\n", + " (0, 0, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0),\n", + " (0, 0, 0, -1, 0, 1, 0, 0, 0, 1, 0, 0),\n", + " (0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, 1, -1, 0, 0, 0, 0, 0, 1, 0, 0),\n", + " (1, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0),\n", + " (0, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0),\n", + " (-1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1),\n", + " (-1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0),\n", + " (-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0),\n", + " (1, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0),\n", + " (0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 1),\n", + " (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1),\n", + " (0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0),\n", + " (0, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0),\n", + " (0, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0),\n", + " (0, 0, 0, 1, 0, 0, 0, 0, 0, 0, -1, 0),\n", + " (0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0),\n", + " (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0),\n", + " (0, 0, 0, 0, 0, 0, 0, -1, 0, 1, 0, 0),\n", + " (0, 0, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0),\n", + " (0, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0),\n", + " (0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0),\n", + " (0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0),\n", + " (1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0),\n", + " (0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0),\n", + " (0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0),\n", + " (1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0),\n", + " (0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0),\n", + " (1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0),\n", + " (0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0),\n", + " (1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0)]" ] }, - "execution_count": 351, + "execution_count": 626, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "Ap, cp, zsol" + "g.vectors" ] }, { "cell_type": "code", - "execution_count": 352, + "execution_count": 574, "metadata": { "collapsed": false }, "outputs": [], "source": [ - "GG = matrix(ZZ, load_42_matrix(\"ejemploucha/ejemplosoto.gro\"))" + "for v in GG:\n", + " if not (v or -v in g.vectors):\n", + " vv = copy(v)\n", + " print v, g.reduce(vv)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "## Ejemplo de Ucha" ] }, { "cell_type": "code", - "execution_count": 353, + "execution_count": 550, "metadata": { "collapsed": false }, - "outputs": [ - { - "data": { - "text/plain": [ - "[-1 0 0 0 0]\n", - "[-1 0 0 1 0]\n", - "[ 0 -1 0 -1 1]\n", - "[ 0 -1 0 0 0]\n", - "[ 0 -1 0 1 0]\n", - "[ 0 0 -1 0 0]\n", - "[ 0 0 -1 0 1]\n", - "[ 0 0 -1 1 0]\n", - "[ 0 0 0 -1 0]\n", - "[ 0 0 0 0 -1]\n", - "[ 0 0 0 1 -1]\n", - "[ 0 1 -1 0 0]\n", - "[ 0 1 -1 1 0]\n", - "[ 0 1 0 0 -1]\n", - "[ 1 -1 0 0 0]\n", - "[ 1 0 -1 0 0]\n", - "[ 1 0 0 0 -1]" - ] - }, - "execution_count": 353, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], + "source": [ + "reset()\n", + "load(\"truncated.py\")\n", + "load(\"resolutor.py\")\n", + "\n", + "def mload_42_matrix(ff):\n", + " \"\"\"docstring for load_42_matrix\"\"\"\n", + " with open(ff) as f:\n", + " s=f.read().splitlines()\n", + " return [line_to_list(l) for l in s[1:]]\n", + "\n", + "\n", + "Ap = matrix(matrix(ZZ, mload_42_matrix(\"ejemploucha/ejemplosoto.mat\"))[0][:5])\n", + "cp = -vector(ZZ, mload_42_matrix(\"ejemploucha/ejemplosoto.cost\")[0])[:5]\n", + "zsol = vector(ZZ,mload_42_matrix(\"ejemploucha/ejemplosoto.zsol\")[0])\n", + "\n", + "b = vector(ZZ,[1415])\n", + "u = vector(ZZ, 5*[1])" + ] + }, + { + "cell_type": "code", + "execution_count": 551, + "metadata": { + "collapsed": false + }, + "outputs": [], "source": [ - "gg = GG.submatrix(0,0,ncols=5)\n", - "gg" + "load(\"resolutor.py\")\n", + "gg = bigsolve(Ap,b,cp,u)" ] }, { "cell_type": "code", - "execution_count": 354, + "execution_count": 552, "metadata": { "collapsed": false }, @@ -685,21 +1063,21 @@ { "data": { "text/plain": [ - "(17, 5)" + "17" ] }, - "execution_count": 354, + "execution_count": 552, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "gg.dimensions()" + "len(gg)" ] }, { "cell_type": "code", - "execution_count": 355, + "execution_count": 553, "metadata": { "collapsed": true }, @@ -710,7 +1088,7 @@ }, { "cell_type": "code", - "execution_count": 356, + "execution_count": 554, "metadata": { "collapsed": false }, @@ -719,7 +1097,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "74 criterion 1, 9 criterion 2, 72 criterion 3, 8 non eligible, 0 equalities, 27 reductions, of which 12 to zero\n" + "74 criterion 1, 9 criterion 2, 72 criterion 3, 10 non feasible, 25 reductions, of which 10 to zero\n" ] } ], @@ -731,7 +1109,7 @@ }, { "cell_type": "code", - "execution_count": 357, + "execution_count": 555, "metadata": { "collapsed": false }, @@ -747,13 +1125,13 @@ " (0, 0, 0, -1, 1),\n", " (0, 0, 1, 1, -1),\n", " (0, 1, -1, -1, 1),\n", - " (-1, 0, 1, 0, 0),\n", " (0, 1, 0, 1, -1),\n", " (-1, 0, 0, 0, 1),\n", " (0, 0, 1, 0, -1),\n", " (0, -1, 0, 0, 1),\n", " (0, 0, 1, -1, 0),\n", " (0, -1, 1, -1, 0),\n", + " (-1, 0, 1, 0, 0),\n", " (0, 1, 0, -1, 0),\n", " (1, 0, 0, -1, 0),\n", " (-1, 1, 0, 1, 0),\n", @@ -761,7 +1139,7 @@ " (-1, 1, 0, 0, 0)]" ] }, - "execution_count": 357, + "execution_count": 555, "metadata": {}, "output_type": "execute_result" } @@ -772,7 +1150,7 @@ }, { "cell_type": "code", - "execution_count": 358, + "execution_count": 556, "metadata": { "collapsed": false }, @@ -783,7 +1161,7 @@ "20" ] }, - "execution_count": 358, + "execution_count": 556, "metadata": {}, "output_type": "execute_result" } @@ -794,7 +1172,7 @@ }, { "cell_type": "code", - "execution_count": 359, + "execution_count": 557, "metadata": { "collapsed": false }, @@ -817,21 +1195,22 @@ }, { "cell_type": "code", - "execution_count": 360, + "execution_count": 558, "metadata": { "collapsed": true }, "outputs": [], "source": [ "for w in gg:\n", - " if not (w in vecs or -w in vecs): print w" + " if not (w in vecs or -w in vecs): print w\n", + " " ] }, { "cell_type": "code", - "execution_count": 361, + "execution_count": 559, "metadata": { - "collapsed": true + "collapsed": false }, "outputs": [], "source": [ @@ -840,7 +1219,7 @@ }, { "cell_type": "code", - "execution_count": 362, + "execution_count": 560, "metadata": { "collapsed": false }, @@ -852,7 +1231,7 @@ }, { "cell_type": "code", - "execution_count": 363, + "execution_count": 561, "metadata": { "collapsed": false }, @@ -860,18 +1239,27 @@ { "data": { "text/plain": [ - "(17, (17, 5))" + "(17, 17)" ] }, - "execution_count": 363, + "execution_count": 561, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "len(g.vectors), gg.dimensions()" + "len(g.vectors), len(gg)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, diff --git a/truncated.py b/truncated.py index 02e6ade..b2b5ed5 100755 --- a/truncated.py +++ b/truncated.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from collections import deque - +import pdb def getz(v): @@ -73,7 +73,12 @@ def max_ppp(z, u, w): if z[l]>0 and z[l]>max(u[l],w[l],0): return False return True - + # + # for (l,v) in enumerate(z): + # if v>0 and v>max(u[l],w[l],0): + # return False + # return True + def max_mmm(z, u, w): """check that z^- ≤ u^- ∨ v^-""" for l in xrange(len(z)): @@ -108,6 +113,9 @@ def pm_split(v): else: um[i]=-a return vector(ZZ,up), vector(ZZ,um) + + + class PartialBasis(object): @@ -123,26 +131,70 @@ def __init__(self, A, c, b, u): self.cv = [] self.Av = [] self.pairs = [] + # + self.vectors_p = [] + self.vectors_m = [] + self.Av_p = [] + self.Av_m = [] + # self.zerox = vector(ZZ,self.n*[0]) self.zerob = vector(ZZ, self.d*[0]) for e in identity_matrix(ZZ,self.n).rows(): self.add_element(e) + + + def supports(self, v): + p, n = [], [] + for (i,c) in enumerate(v): + if c>0: + p.append(i) + elif c<0: + n.append(i) + return (p,n) + + def binomial_order(self, b): + """docstring for binomial_order""" + c = b*self.c + minux = False + if c<0: + minux = True + elif c == 0: + for k in xrange(self.n): + l = self.n-k-1 + if b[l]>0: + minux = True + break + elif b[l]<0: + minux = False + break + else: + raise RuntimeError("Sorting the zero vector!! %s" % v) + if minux: + for (i,v) in enumerate(b): + b[i] *= -1 + return abs(c) + - # def set_to_Au(self, v, u): - # """set vector v to A*u""" - - def add_element(self, v): + def add_element(self, e): """ add element e to partial basis, update critical pairs to be computed, and precompute as much stuff as possible for reduction. """ - cv = self.c*v - e = v if cv>0 else -v # this makes sure that e^+ >_c e^-. + c = self.binomial_order(e) l = len(self.vectors) + Av = self.A*e + p,m = self.supports(e) + Ap,Am = self.supports(Av) + self.vectors.append(e) - self.cv.append(abs(cv)) - self.Av.append(self.A*e) + self.cv.append(abs(c)) + self.Av.append(Av) + self.vectors_p.append(set(p)) + self.vectors_m.append(set(m)) + self.Av_p.append(set(Ap)) + self.Av_m.append(set(Am)) + if l: # true if this is not the first vector for i in xrange(l): self.pairs.append((i,l)) @@ -151,6 +203,10 @@ def pop_element(self, i): self.vectors.pop(i) self.cv.pop(i) self.Av.pop(i) + self.vectors_p.pop(i) + self.vectors_m.pop(i) + self.Av_m.pop(i) + self.Av_p.pop(i) # for (j,p) in self.pairs: # if i in p: # self.pairs.pop(j) @@ -161,24 +217,31 @@ def criterion_1(self, i, j): its leading terms are disjoint. """ # print self.vectors[i], self.vectors[j], self.Av[i], self.Av[j] - return ( - (disjoint_pp(self.Av[i], self.Av[j])) and - disjoint_pp(self.vectors[i], self.vectors[j]) and - disjoint_mm(self.vectors[i], self.vectors[j]) - ) + # return ( + # (disjoint_pp(self.Av[i], self.Av[j])) and + # disjoint_pp(self.vectors[i], self.vectors[j]) and + # disjoint_mm(self.vectors[i], self.vectors[j]) + # ) + # pdb.set_trace() + return not ( + bool(self.Av_p[i].intersection(self.Av_p[j])) or + bool(self.vectors_p[i].intersection(self.vectors_p[j])) or + bool(self.vectors_m[i].intersection(self.vectors_m[j])) + ) def criterion_3(self, i, j): """Malkin's criterion.""" # print self.vectors[i], self.vectors[j], self.Av[i], self.Av[j] - return ( - (not disjoint_mm(self.Av[i], self.Av[j])) or - (not disjoint_pp(self.vectors[i], self.vectors[j])) or - (not disjoint_mm(self.vectors[i], self.vectors[j])) - ) - # return ( + # return ( # (not disjoint_mm(self.Av[i], self.Av[j])) or + # (not disjoint_pp(self.vectors[i], self.vectors[j])) or # (not disjoint_mm(self.vectors[i], self.vectors[j])) # ) + return ( + bool(self.Av_m[i].intersection(self.Av_m[j])) or + bool(self.vectors_p[i].intersection(self.vectors_p[j])) or + bool(self.vectors_m[i].intersection(self.vectors_m[j])) + ) def criterion_2(self, i, j): @@ -302,30 +365,30 @@ def reduce(self, v, by=None): return w - # def self_reduce(self): - # """self_reduce the basis.""" - # b = len(self.vectors) - # i = 0 - # while i Date: Tue, 4 Apr 2017 14:08:24 +0200 Subject: [PATCH 13/15] Removed order, and use new pm_split --- truncated.py | 48 ++---------------------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/truncated.py b/truncated.py index b2b5ed5..619c60d 100755 --- a/truncated.py +++ b/truncated.py @@ -114,8 +114,6 @@ def pm_split(v): um[i]=-a return vector(ZZ,up), vector(ZZ,um) - - class PartialBasis(object): @@ -216,13 +214,6 @@ def criterion_1(self, i, j): The S-poly of the pair (i,j) is skippable if its leading terms are disjoint. """ - # print self.vectors[i], self.vectors[j], self.Av[i], self.Av[j] - # return ( - # (disjoint_pp(self.Av[i], self.Av[j])) and - # disjoint_pp(self.vectors[i], self.vectors[j]) and - # disjoint_mm(self.vectors[i], self.vectors[j]) - # ) - # pdb.set_trace() return not ( bool(self.Av_p[i].intersection(self.Av_p[j])) or bool(self.vectors_p[i].intersection(self.vectors_p[j])) or @@ -231,12 +222,6 @@ def criterion_1(self, i, j): def criterion_3(self, i, j): """Malkin's criterion.""" - # print self.vectors[i], self.vectors[j], self.Av[i], self.Av[j] - # return ( - # (not disjoint_mm(self.Av[i], self.Av[j])) or - # (not disjoint_pp(self.vectors[i], self.vectors[j])) or - # (not disjoint_mm(self.vectors[i], self.vectors[j])) - # ) return ( bool(self.Av_m[i].intersection(self.Av_m[j])) or bool(self.vectors_p[i].intersection(self.vectors_p[j])) or @@ -330,10 +315,6 @@ def reduce_by_ith(self, s, As, i): if round == 0: return False, False else: - - - - return w, Aw @@ -400,7 +381,7 @@ def next_pair(self): """docstring for pop""" return self.pairs.pop() - def pm_split(v): + def pm_split(self, v): """ slightly faster than pm_split2""" up = copy(self.zerox) um = copy(self.zerox) @@ -414,35 +395,10 @@ def pm_split(v): def feasible(self, v): """docstring for feasible""" if let_pp(v,self.u) and let_mp(v,self.u): - avp, avm = pm_split(v) + avp, avm = self.pm_split(v) return let(self.A*avp, self.b) and let(self.A*avm, self.b) return False - def order(self, i,j): - """ - Set i, j in gr-rev-lex order: - - vi > vj if c*vi > c*vj or - equality and the last nonzero coordinate of vi-vj is negative. - - We sort indices and not vectors so that we don't have to compute - c*v and c*v more than once. - """ - if self.cv[i]>self.cv[j]: - return (i,j) - elif self.cv[i] v[l] : - return (j,i) - elif u[l] < v[l] : - return (i,j) - # The vectors are equal. This should never happen: - raise RuntimeError("Vectors %s and %s are equal (%s and %s)" % (i,j,self.vectors[i], self.vectors[j])) From b576e5dd4140f55c28da62c3809cde3967e5812c Mon Sep 17 00:00:00 2001 From: anteprandium Date: Thu, 6 Apr 2017 11:38:39 +0200 Subject: [PATCH 14/15] commit pre-unvector --- truncated.py | 222 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 144 insertions(+), 78 deletions(-) diff --git a/truncated.py b/truncated.py index 619c60d..4199eff 100755 --- a/truncated.py +++ b/truncated.py @@ -1,13 +1,21 @@ #!/usr/bin/env python -from collections import deque +from collections import deque +from itertools import izip import pdb +def matprod(A,b): + return [sum(ai*bi for ai,bi in izip(row, b)) for row in A] + +def dotprod(u,v): + return sum(ui*vi for (ui,vi) in izip(u,v)) + + def getz(v): """Check if v is greater or equal than zero, component-wise.""" # return all(vi>=0 for vi in v) #(Slower by a factor of 2) - for vi in v: + for vi in v: if vi<0: return False return True @@ -78,7 +86,7 @@ def max_ppp(z, u, w): # if v>0 and v>max(u[l],w[l],0): # return False # return True - + def max_mmm(z, u, w): """check that z^- ≤ u^- ∨ v^-""" for l in xrange(len(z)): @@ -113,7 +121,7 @@ def pm_split(v): else: um[i]=-a return vector(ZZ,up), vector(ZZ,um) - + class PartialBasis(object): @@ -139,8 +147,8 @@ def __init__(self, A, c, b, u): self.zerob = vector(ZZ, self.d*[0]) for e in identity_matrix(ZZ,self.n).rows(): self.add_element(e) - - + + def supports(self, v): p, n = [], [] for (i,c) in enumerate(v): @@ -148,8 +156,8 @@ def supports(self, v): p.append(i) elif c<0: n.append(i) - return (p,n) - + return (set(p),set(n)) + def binomial_order(self, b): """docstring for binomial_order""" c = b*self.c @@ -169,12 +177,12 @@ def binomial_order(self, b): raise RuntimeError("Sorting the zero vector!! %s" % v) if minux: for (i,v) in enumerate(b): - b[i] *= -1 + b[i] = -v return abs(c) - - - def add_element(self, e): + + + def add_element(self, e, pos=None, pairs=True): """ add element e to partial basis, update critical pairs to be computed, and precompute as much stuff as possible for reduction. @@ -184,20 +192,33 @@ def add_element(self, e): Av = self.A*e p,m = self.supports(e) Ap,Am = self.supports(Av) - - self.vectors.append(e) - self.cv.append(abs(c)) - self.Av.append(Av) - self.vectors_p.append(set(p)) - self.vectors_m.append(set(m)) - self.Av_p.append(set(Ap)) - self.Av_m.append(set(Am)) - - if l: # true if this is not the first vector + + if pos is None: + self.vectors.append(e) + self.cv.append(c) + self.Av.append(Av) + self.vectors_p.append(p) + self.vectors_m.append(m) + self.Av_p.append(Ap) + self.Av_m.append(Am) + else: + i = pos + self.vectors[i]=e + self.cv[i]=c + self.Av[i]=Av + self.vectors_p[i]=set(p) + self.vectors_m[i]=set(m) + self.Av_p[i]=Ap + self.Av_m[i]=Am + + + + if pairs and l: # true if this is not the first vector for i in xrange(l): - self.pairs.append((i,l)) + self.pairs.append([i,l]) + - def pop_element(self, i): + def pop_element(self, i, pairs=False): self.vectors.pop(i) self.cv.pop(i) self.Av.pop(i) @@ -205,9 +226,37 @@ def pop_element(self, i): self.vectors_m.pop(i) self.Av_m.pop(i) self.Av_p.pop(i) - # for (j,p) in self.pairs: - # if i in p: - # self.pairs.pop(j) + if pairs: + j = 0 + l = len(self.pairs) + while j=len(self.vectors):print 30*"-", "problem: %s at %s %s (len=%s)" % (i,j,p, len(self.vectors)) + + j += 1 + elif p[0]=len(self.vectors):print 30*"-", "problem: %s at %s %s (len=%s)" % (i,j,p, len(self.vectors)) + + j += 1 + else: + # print "nothing at %s, %s, %s" % (j,p,i) + j += 1 + + + # print len(self.vectors) + # print self.pairs + + + def criterion_1(self, i, j): """True if (i,j) is skipabble: @@ -218,7 +267,7 @@ def criterion_1(self, i, j): bool(self.Av_p[i].intersection(self.Av_p[j])) or bool(self.vectors_p[i].intersection(self.vectors_p[j])) or bool(self.vectors_m[i].intersection(self.vectors_m[j])) - ) + ) def criterion_3(self, i, j): """Malkin's criterion.""" @@ -279,29 +328,29 @@ def reduce_by_ith(self, s, As, i): w = s Aw = As - if isz(w): return w, Aw + # if isz(w): return w, Aw while True: - if let_pp(v,w) and let_mm(v,w) and let_pp(Av, Aw): + if let_pp(Av, Aw) and let_pp(v,w) and let_mm(v,w) : # w is reducible round += 1 # w = w-v, but modify in place. for k in xrange(self.n): w[k]-=v[k] # Aw = Aw-Av - for k in xrange(len(Aw)): + for k in xrange(self.d): Aw[k] -= Av[k] # # slower alternative: # w -= v # Aw -= Av - elif let_pm(v,w) and let_mp(v,w) and let_pm(Av, Aw): + elif let_pm(Av, Aw) and let_pm(v,w) and let_mp(v,w) : # -w is reducible round += 1 # w = -w-v for k in xrange(self.n): w[k]=-w[k]-v[k] # Aw = -A*w-A*v - for k in xrange(len(Aw)): + for k in xrange(self.d): Aw[k] = -Aw[k]-Av[k] # # slower: # w *= -1 @@ -317,7 +366,6 @@ def reduce_by_ith(self, s, As, i): else: return w, Aw - def reduce(self, v, by=None): """reduce""" l = len(self.vectors) @@ -332,15 +380,18 @@ def reduce(self, v, by=None): # Aw = copy(self.zerob) # for k in xrange(self.d): # Aw[k] = sum(self.A[k,l]*w[l] for l in xrange(self.n)) - while i200: break + + while g.pairs: # or unfinished? + if len(g.vectors)>2000: break i, j = g.next_pair() if g.criterion_1(i,j): @@ -437,27 +504,26 @@ def bubu(A,b,c,u): c3 += 1 continue - if g.criterion_2(i,j): # Gebauer and Möller criterion - c2 += 1 - continue - - - - - # At this point, cv < cw. - # 2.2.1 - # r = g.vectors[i] - # r -= g.vectors[j] + # if g.criterion_2(i,j): # Gebauer and Möller criterion + # c2 += 1 + # continue + + + + # consider u[i]-u[j] r = copy(g.zerox) for l in xrange(g.n): r[l] = g.vectors[j][l]-g.vectors[i][l] g.binomial_order(r) - - + + if g.feasible(r): rx +=1 - if (rx%1000) == 0: + if (rx%interval) == 0: print "reduction: %s, basis: %s." % (rx, len(g.vectors)) + # g.clean() + # g.self_reduce() + print "Down to %s" % len(g.vectors) c = g.reduce(r) if not isz(c): g.add_element(c) @@ -480,7 +546,7 @@ def bubu(A,b,c,u): u1 = vector(ZZ, 7*[38]) -B = matrix(ZZ, [ +B = matrix(ZZ, [ [9, 6, 6, 8, 3, 6, 2, 4, 6, 3, 9, 4, 4, 8, 6, 9, 4, 2, 8, 8], [8, 8, 0, 5, 4, 4, 7, 0, 2, 3, 0, 6, 7, 7, 0, 6, 7, 8, 6, 0], [0, 9, 4, 1, 2, 0, 6, 5, 8, 5, 5, 5, 0, 0, 9, 3, 1, 8, 4, 8], @@ -488,6 +554,6 @@ def bubu(A,b,c,u): [3, 0, 2, 7, 5, 8, 1, 2, 1, 5, 7, 8, 3, 8, 4, 3, 6, 2, 9, 3], ]) c2 = vector(ZZ,[3, 2, 9, 1, 7, 5, 6, 2, 7, 8, 6, 9, 2, 6, 8, 7, 6, 2, 2, 1]) -b2 = vector(ZZ, 5*[50]) +b2 = vector(ZZ, 5*[20]) u2 = vector(ZZ, 20*[1]) From 8ef887e78266e8a9b83ee55e44f65ff25542c7c9 Mon Sep 17 00:00:00 2001 From: anteprandium Date: Fri, 7 Apr 2017 11:12:55 +0200 Subject: [PATCH 15/15] pre-basiselement --- truncated.py | 58 +++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/truncated.py b/truncated.py index 4199eff..3830136 100755 --- a/truncated.py +++ b/truncated.py @@ -1,13 +1,13 @@ #!/usr/bin/env python -from collections import deque -from itertools import izip +from collections import deque +from itertools import izip, imap import pdb def matprod(A,b): return [sum(ai*bi for ai,bi in izip(row, b)) for row in A] - + def dotprod(u,v): return sum(ui*vi for (ui,vi) in izip(u,v)) @@ -42,6 +42,7 @@ def let_pp(a,b): return False return True + def let_pm(a,b): "True if and only if a^+ is less or equal than b^-." for i in xrange(len(a)): @@ -123,7 +124,6 @@ def pm_split(v): return vector(ZZ,up), vector(ZZ,um) - class PartialBasis(object): """docstring for PartialBasis""" def __init__(self, A, c, b, u): @@ -146,7 +146,8 @@ def __init__(self, A, c, b, u): self.zerox = vector(ZZ,self.n*[0]) self.zerob = vector(ZZ, self.d*[0]) for e in identity_matrix(ZZ,self.n).rows(): - self.add_element(e) + self.add_element(copy(e)) + def supports(self, v): @@ -216,7 +217,7 @@ def add_element(self, e, pos=None, pairs=True): if pairs and l: # true if this is not the first vector for i in xrange(l): self.pairs.append([i,l]) - + def pop_element(self, i, pairs=False): self.vectors.pop(i) @@ -228,7 +229,7 @@ def pop_element(self, i, pairs=False): self.Av_p.pop(i) if pairs: j = 0 - l = len(self.pairs) + l = len(self.pairs) while j=len(self.vectors):print 30*"-", "problem: %s at %s %s (len=%s)" % (i,j,p, len(self.vectors)) - + j += 1 elif p[0]=len(self.vectors):print 30*"-", "problem: %s at %s %s (len=%s)" % (i,j,p, len(self.vectors)) - + j += 1 else: # print "nothing at %s, %s, %s" % (j,p,i) j += 1 - - + + # print len(self.vectors) # print self.pairs - - + + def criterion_1(self, i, j): @@ -309,7 +310,7 @@ def criterion_2(self, i, j): return False - def reduce_by_ith(self, s, As, i): + def reduce_by_ith(self, w, Aw, i): """ It modifies s and As in place!!! @@ -325,9 +326,6 @@ def reduce_by_ith(self, s, As, i): v = self.vectors[i] Av = self.Av[i] - w = s - Aw = As - # if isz(w): return w, Aw while True: @@ -387,11 +385,9 @@ def reduce(self, v, by=None): i += 1 else: # i.e, if r is a true reduction. - #### TODO: check this is OK. # rotate the list and start over - # indices.rotate(i+1) - # i = 0 - i += 1 + indices.rotate(i+1) + i = 0 w = r Aw = Ar return w @@ -416,12 +412,13 @@ def self_reduce(self): self.add_element(w,pos=i,pairs=False) # don't update the pairs i +=1 - def clean(self): + def clean(self, pairs=True): b = len(self.vectors) i = 0 while i2000: break i, j = g.next_pair() @@ -523,7 +526,6 @@ def bubu(A,b,c,u, interval=1000): print "reduction: %s, basis: %s." % (rx, len(g.vectors)) # g.clean() # g.self_reduce() - print "Down to %s" % len(g.vectors) c = g.reduce(r) if not isz(c): g.add_element(c) @@ -546,7 +548,7 @@ def bubu(A,b,c,u, interval=1000): u1 = vector(ZZ, 7*[38]) -B = matrix(ZZ, [ +B = matrix(ZZ, [ [9, 6, 6, 8, 3, 6, 2, 4, 6, 3, 9, 4, 4, 8, 6, 9, 4, 2, 8, 8], [8, 8, 0, 5, 4, 4, 7, 0, 2, 3, 0, 6, 7, 7, 0, 6, 7, 8, 6, 0], [0, 9, 4, 1, 2, 0, 6, 5, 8, 5, 5, 5, 0, 0, 9, 3, 1, 8, 4, 8],