[zypp-commit] r8163 - in /trunk/sat-solver: bindings/ruby/tests/decisions.rb bindings/satsolver.i src/solver.c src/solver.h
Author: kkaempf Date: Sun Dec 30 17:58:01 2007 New Revision: 8163 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8163&view=rev Log: add Decision (solver result element) and testcase Added: trunk/sat-solver/bindings/ruby/tests/decisions.rb Modified: trunk/sat-solver/bindings/satsolver.i trunk/sat-solver/src/solver.c trunk/sat-solver/src/solver.h Added: trunk/sat-solver/bindings/ruby/tests/decisions.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/decisions.rb?rev=8163&view=auto ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/decisions.rb (added) +++ trunk/sat-solver/bindings/ruby/tests/decisions.rb Sun Dec 30 17:58:01 2007 @@ -0,0 +1,62 @@ +$: << "../../../build/bindings/ruby" +# test Decisions +require 'test/unit' +require 'satsolver' + +class DecisionTest < Test::Unit::TestCase + def test_decision + pool = SatSolver::Pool.new + assert pool + pool.arch = "i686" + + installed = pool.create_repo( 'system' ) + assert installed + installed.create_solvable( 'A', '0.0-0' ) + installed.create_solvable( 'B', '1.0-0' ) + installed.create_solvable( 'C', '2.0-0' ) + installed.create_solvable( 'D', '3.0-0' ) + + repo = pool.create_repo( 'test' ) + assert repo + + solv1 = repo.create_solvable( 'A', '1.0-0' ) + assert solv1 + solv1.obsoletes << SatSolver::Relation.new( pool, "C" ) + solv1.requires << SatSolver::Relation.new( pool, "B", SatSolver::REL_GE, "2.0-0" ) + + solv2 = repo.create_solvable( 'B', '2.0-0', 'noarch' ) + assert solv2 + + solv3 = repo.create_solvable( 'CC', '3.3-0', 'noarch' ) + solv3.requires << SatSolver::Relation.new( pool, "A", SatSolver::REL_GT, "0.0-0" ) + repo.create_solvable( 'DD', '4.4-0', 'noarch' ) + + + transaction = pool.create_transaction + transaction.install( solv3 ) + transaction.remove( "D" ) + + solver = pool.create_solver( installed ) + solver.allow_uninstall = 1; +# @pool.debug = 255 + solver.solve( transaction ) + puts "#{solver.problem_count} problems found" + assert solver.decision_count > 0 + i = 0 + solver.each_decision { |d| + i += 1 + case d.op + when SatSolver::DEC_INSTALL + puts "#{i}: Install #{d.solvable} #{d.reason}" + when SatSolver::DEC_REMOVE + puts "#{i}: Remove #{d.solvable} #{d.reason}" + when SatSolver::DEC_OBSOLETE + puts "#{i}: Obsolete #{d.solvable} #{d.reason}" + when SatSolver::DEC_UPDATE + puts "#{i}: Update #{d.solvable} #{d.reason}" + else + puts "#{i}: Decision op #{d.op}" + end + } + end +end Modified: trunk/sat-solver/bindings/satsolver.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/satsolver.i?rev=8163&r1=8162&r2=8163&view=diff ============================================================================== --- trunk/sat-solver/bindings/satsolver.i (original) +++ trunk/sat-solver/bindings/satsolver.i Sun Dec 30 17:58:01 2007 @@ -151,6 +151,29 @@ free( t ); } +#define DEC_INSTALL 1 +#define DEC_REMOVE 2 +#define DEC_UPDATE 3 +#define DEC_OBSOLETE 4 + +typedef struct _Decision { + int op; /* DEC_{INSTALL,UPDATE,OBSOLETE,REMOVE} */ + Solvable *solvable; + Solvable *reason; +} Decision; + +static Decision *decision_new( int op, Solvable *solvable, Solvable *reason ) +{ + Decision *d = (Decision *)malloc( sizeof( Decision )); + d->op = op; + d->solvable = solvable; + d->reason = reason; + return d; +} + +typedef struct _Problem { +} Problem; + %} /*-------------------------------------------------------------*/ @@ -199,6 +222,14 @@ %rename(Solver) solver; typedef struct solver {} Solver; +%nodefault _Decision; +%rename(Decision) _Decision; +typedef struct _Decision {} Decision; + +%nodefault _Problem; +%rename(Problem) _Problem; +typedef struct _Problem {} Problem; + /*-------------------------------------------------------------*/ /* Pool */ @@ -801,6 +832,27 @@ } /*-------------------------------------------------------------*/ +/* Decision */ + +%extend Decision { + %constant int DEC_INSTALL = 1; + %constant int DEC_REMOVE = 2; + %constant int DEC_UPDATE = 3; + %constant int DEC_OBSOLETE = 4; + + Decision( int op, Solvable *solvable, Solvable *reason = NULL ) + { return decision_new( op, solvable, reason ); } + ~Decision() + { free( $self ); } + int op() + { return $self->op; } + Solvable *solvable() + { return $self->solvable; } + Solvable *reason() + { return $self->reason; } +} + +/*-------------------------------------------------------------*/ /* Solver */ %extend Solver { @@ -855,6 +907,73 @@ void solve( Transaction *t ) { solver_solve( $self, &(t->queue)); } + int decision_count() + { return $self->decisionq.count; } +#if defined(SWIGRUBY) + void each_decision() + { + Pool *pool = $self->pool; + Repo *installed = $self->installed; + Id p, *obsoletesmap = create_obsoletesmap( $self ); + Solvable *s, *r; + int op; + Decision *d; + + if (installed) { + FOR_REPO_SOLVABLES(installed, p, s) { + if ($self->decisionmap[p] >= 0) + continue; + if (obsoletesmap[p]) { + d = decision_new( DEC_OBSOLETE, s, pool_id2solvable( pool, obsoletesmap[p] ) ); + } + else { + d = decision_new( DEC_REMOVE, s, NULL ); + } + rb_yield(SWIG_NewPointerObj((void*) d, SWIGTYPE_p__Decision, 0)); + } + } + + int i; + for ( i = 0; i < $self->decisionq.count; i++) + { + p = $self->decisionq.elements[i]; + + if (p < 0) { /* remove */ + continue; + } + else if (p == SYSTEMSOLVABLE) { + continue; + } + s = pool->solvables + p; + r = NULL; + if (installed && s->repo == installed) + continue; + + if (!obsoletesmap[p]) { + op = DEC_INSTALL; + } + else { + op = DEC_UPDATE; + int j; + for (j = installed->start; j < installed->end; j++) { + if (obsoletesmap[j] == p) { + r = pool_id2solvable( pool, j ); + break; + } + } + } + d = decision_new( op, s, r ); + rb_yield(SWIG_NewPointerObj((void*) d, SWIGTYPE_p__Decision, 0)); + } + } +#endif + int problem_count() + { return $self->problems.count; } +#if defined(SWIGRUBY) + %rename("problems?") problems_found(); +#endif + int problems_found() + { return $self->problems.count != 0; } void print_decisions() { printdecisions( $self ); } @@ -896,6 +1015,17 @@ rb_yield(SWIG_NewPointerObj((void*) s, SWIGTYPE_p__Solvable, 0)); } } + + void each_suggested() + { + int i; + Solvable *s; + for (i = 0; i < $self->suggestions.count; i++) { + s = $self->pool->solvables + $self->suggestions.elements[i]; + rb_yield(SWIG_NewPointerObj((void*) s, SWIGTYPE_p__Solvable, 0)); + } + } + #endif }; Modified: trunk/sat-solver/src/solver.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/solver.c?rev=8163&r1=8162&r2=8163&view=diff ============================================================================== --- trunk/sat-solver/src/solver.c (original) +++ trunk/sat-solver/src/solver.c Sun Dec 30 17:58:01 2007 @@ -2622,23 +2622,20 @@ } - /* - * printdecisions + * create obsoletesmap from solver decisions + * required for decision handling */ - -void -printdecisions(Solver *solv) +Id * +create_obsoletesmap(Solver *solv) { Pool *pool = solv->pool; Repo *installed = solv->installed; - Id p, *obsoletesmap; + Id p, *obsoletesmap = NULL; int i; Solvable *s; - POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n"); - obsoletesmap = (Id *)xcalloc(pool->nsolvables, sizeof(Id)); if (installed) { @@ -2691,6 +2688,24 @@ } } } + return obsoletesmap; +} + +/* + * printdecisions + */ + + +void +printdecisions(Solver *solv) +{ + Pool *pool = solv->pool; + Repo *installed = solv->installed; + Id p, *obsoletesmap = create_obsoletesmap( solv ); + int i; + Solvable *s; + + POOL_DEBUG(SAT_DEBUG_SCHUBI, "----- Decisions -----\n"); /* print solvables to be erased */ Modified: trunk/sat-solver/src/solver.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/solver.h?rev=8163&r1=8162&r2=8163&view=diff ============================================================================== --- trunk/sat-solver/src/solver.h (original) +++ trunk/sat-solver/src/solver.h Sun Dec 30 17:58:01 2007 @@ -145,6 +145,8 @@ extern Id solver_findproblemrule(Solver *solv, Id problem); extern SolverProbleminfo solver_problemruleinfo(Solver *solv, Queue *job, Id rid, Id *depp, Id *sourcep, Id *targetp); +Id *create_obsoletesmap(Solver *solv); + /* debug functions, do not use */ void printdecisions(Solver *solv); void printsolutions(Solver *solv, Queue *job); -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org
participants (1)
-
kkaempf@svn.opensuse.org