Mailinglist Archive: zypp-commit (171 mails)

< Previous Next >
[zypp-commit] <sat-solver> master : - add solver_take_solution() function
  • From: Michael Schroeder <mls@xxxxxxx>
  • Date: Wed, 17 Jun 2009 11:08:51 +0200
  • Message-id: <E1MGr9r-0007RQ-Lo@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 027ec47f07bed550064b681cae45cbac9d889d5f
Author: Michael Schroeder <mls@xxxxxxx>
Date: Wed Jun 17 11:08:51 2009 +0200

- add solver_take_solution() function
- add solver_printsolution() function
- rename solver_printsolutions() to solver_printallsolutions()
- add transaction_init_clone() and transaction_free_orderdata()
---
src/problems.c | 35 +++++++
src/problems.h | 3 +
src/solverdebug.c | 215 ++++++++++++++++++++++--------------------
src/solverdebug.h | 5 +-
src/transaction.c | 37 +++++++
src/transaction.h | 2 +
tests/solver/deptestomatic.c | 2 +-
tests/solver/yps.c | 2 +-
8 files changed, 194 insertions(+), 107 deletions(-)

diff --git a/src/problems.c b/src/problems.c
index bed7303..57bb545 100644
--- a/src/problems.c
+++ b/src/problems.c
@@ -686,6 +686,41 @@ solver_next_solutionelement(Solver *solv, Id problem, Id
solution, Id element, I
return element + 1;
}

+void
+solver_take_solutionelement(Solver *solv, Id p, Id rp, Queue *job)
+{
+ int i;
+
+ if (p == SOLVER_SOLUTION_JOB)
+ {
+ job->elements[rp - 1] = SOLVER_NOOP;
+ job->elements[rp] = 0;
+ return;
+ }
+ if (rp <= 0 && p <= 0)
+ return; /* just in case */
+ if (rp > 0)
+ p = SOLVER_INSTALL|SOLVER_SOLVABLE;
+ else
+ {
+ rp = p;
+ p = SOLVER_ERASE|SOLVER_SOLVABLE;
+ }
+ for (i = 0; i < job->count; i += 2)
+ if (job->elements[i] == p && job->elements[i + 2] == rp)
+ return;
+ queue_push2(job, p, rp);
+}
+
+void
+solver_take_solution(Solver *solv, Id problem, Id solution, Queue *job)
+{
+ Id p, rp, element = 0;
+ while ((element = solver_next_solutionelement(solv, problem, solution,
element, &p, &rp)) != 0)
+ solver_take_solutionelement(solv, p, rp, job);
+}
+
+
/*-------------------------------------------------------------------
*
* find problem rule
diff --git a/src/problems.h b/src/problems.h
index fad8834..b2ed55b 100644
--- a/src/problems.h
+++ b/src/problems.h
@@ -35,6 +35,9 @@ Id solver_next_solution(struct _Solver *solv, Id problem, Id
solution);
Id solver_solutionelement_count(struct _Solver *solv, Id problem, Id solution);
Id solver_next_solutionelement(struct _Solver *solv, Id problem, Id solution,
Id element, Id *p, Id *rp);

+void solver_take_solutionelement(struct _Solver *solv, Id p, Id rp, Queue
*job);
+void solver_take_solution(struct _Solver *solv, Id problem, Id solution, Queue
*job);
+
Id solver_findproblemrule(struct _Solver *solv, Id problem);
void solver_findallproblemrules(struct _Solver *solv, Id problem, Queue
*rules);

diff --git a/src/solverdebug.c b/src/solverdebug.c
index c0759f2..1970f75 100644
--- a/src/solverdebug.c
+++ b/src/solverdebug.c
@@ -501,14 +501,14 @@ solver_printtransaction(Solver *solv)
}

void
-solver_printprobleminfo(Solver *solv, Queue *job, Id problem)
+solver_printprobleminfo(Solver *solv, Id problem)
{
Pool *pool = solv->pool;
Id probr;
Id dep, source, target;

probr = solver_findproblemrule(solv, problem);
- switch (solver_problemruleinfo(solv, job, probr, &dep, &source, &target))
+ switch (solver_ruleinfo(solv, probr, &source, &target, &dep))
{
case SOLVER_RULE_DISTUPGRADE:
POOL_DEBUG(SAT_DEBUG_RESULT, "%s does not belong to a distupgrade
repository\n", solvid2str(pool, source));
@@ -561,121 +561,130 @@ solver_printprobleminfo(Solver *solv, Queue *job, Id
problem)
}

void
-solver_printsolutions(Solver *solv, Queue *job)
+solver_printsolution(Solver *solv, Id problem, Id solution)
{
Pool *pool = solv->pool;
- int pcnt;
- Id p, rp, how, what, select;
- Id problem, solution, element;
+ Id p, rp, element, how, what, select;
Solvable *s, *sd;

- POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the
solutions:\n\n");
- pcnt = 1;
- problem = 0;
- while ((problem = solver_next_problem(solv, problem)) != 0)
+ element = 0;
+ while ((element = solver_next_solutionelement(solv, problem, solution,
element, &p, &rp)) != 0)
{
- POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt++);
- POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
- solver_printprobleminfo(solv, job, problem);
- POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
- solution = 0;
- while ((solution = solver_next_solution(solv, problem, solution)) != 0)
- {
- element = 0;
- while ((element = solver_next_solutionelement(solv, problem,
solution, element, &p, &rp)) != 0)
+ if (p == SOLVER_SOLUTION_JOB)
+ {
+ /* job, rp is index into job queue */
+ how = solv->job.elements[rp - 1];
+ what = solv->job.elements[rp];
+ select = how & SOLVER_SELECTMASK;
+ switch (how & SOLVER_JOBMASK)
{
- if (p == SOLVER_SOLUTION_JOB)
- {
- /* job, rp is index into job queue */
- how = job->elements[rp - 1];
- what = job->elements[rp];
- select = how & SOLVER_SELECTMASK;
- switch (how & SOLVER_JOBMASK)
- {
- case SOLVER_INSTALL:
- if (select == SOLVER_SOLVABLE && solv->installed &&
pool->solvables[what].repo == solv->installed)
- POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s
installed\n", solvid2str(pool, what));
- else if (select == SOLVER_SOLVABLE_PROVIDES)
- POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a
solvable %s\n", solver_select2str(solv, select, what));
- else
- POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n",
solver_select2str(solv, select, what));
- break;
- case SOLVER_ERASE:
- if (select == SOLVER_SOLVABLE && !(solv->installed &&
pool->solvables[what].repo == solv->installed))
- POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid
installation of %s\n", solvid2str(pool, what));
- else if (select == SOLVER_SOLVABLE_PROVIDES)
- POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all
solvables %s\n", solver_select2str(solv, select, what));
- else
- POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n",
solver_select2str(solv, select, what));
- break;
- case SOLVER_UPDATE:
- POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most
recent version of %s\n", solver_select2str(solv, select, what));
- break;
- case SOLVER_LOCK:
- POOL_DEBUG(SAT_DEBUG_RESULT, "- do not lock %s\n",
solver_select2str(solv, select, what));
- break;
- default:
- POOL_DEBUG(SAT_DEBUG_RESULT, "- do something
different\n");
- break;
- }
- }
- else if (p == SOLVER_SOLUTION_INFARCH)
+ case SOLVER_INSTALL:
+ if (select == SOLVER_SOLVABLE && solv->installed &&
pool->solvables[what].repo == solv->installed)
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- do not keep %s installed\n",
solvid2str(pool, what));
+ else if (select == SOLVER_SOLVABLE_PROVIDES)
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install a solvable
%s\n", solver_select2str(solv, select, what));
+ else
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install %s\n",
solver_select2str(solv, select, what));
+ break;
+ case SOLVER_ERASE:
+ if (select == SOLVER_SOLVABLE && !(solv->installed &&
pool->solvables[what].repo == solv->installed))
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- do not forbid installation of
%s\n", solvid2str(pool, what));
+ else if (select == SOLVER_SOLVABLE_PROVIDES)
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall all solvables
%s\n", solver_select2str(solv, select, what));
+ else
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- do not deinstall %s\n",
solver_select2str(solv, select, what));
+ break;
+ case SOLVER_UPDATE:
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- do not install most recent
version of %s\n", solver_select2str(solv, select, what));
+ break;
+ case SOLVER_LOCK:
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- do not lock %s\n",
solver_select2str(solv, select, what));
+ break;
+ default:
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- do something different\n");
+ break;
+ }
+ }
+ else if (p == SOLVER_SOLUTION_INFARCH)
+ {
+ s = pool->solvables + rp;
+ if (solv->installed && s->repo == solv->installed)
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- keep %s despite the inferior
architecture\n", solvable2str(pool, s));
+ else
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- install %s despite the inferior
architecture\n", solvable2str(pool, s));
+ }
+ else if (p == SOLVER_SOLUTION_DISTUPGRADE)
+ {
+ s = pool->solvables + rp;
+ if (solv->installed && s->repo == solv->installed)
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- keep obsolete %s\n",
solvable2str(pool, s));
+ else
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- install %s from excluded
repository\n", solvable2str(pool, s));
+ }
+ else
+ {
+ /* policy, replace p with rp */
+ s = pool->solvables + p;
+ sd = rp ? pool->solvables + rp : 0;
+ if (s == sd && solv->distupgrade)
+ {
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- keep obsolete %s\n",
solvable2str(pool, s));
+ }
+ else if (sd)
+ {
+ int gotone = 0;
+ if (!solv->allowdowngrade && evrcmp(pool, s->evr, sd->evr,
EVRCMP_MATCH_RELEASE) > 0)
{
- s = pool->solvables + rp;
- if (solv->installed && s->repo == solv->installed)
- POOL_DEBUG(SAT_DEBUG_RESULT, "- keep %s despite the
inferior architecture\n", solvable2str(pool, s));
- else
- POOL_DEBUG(SAT_DEBUG_RESULT, "- install %s despite the
inferior architecture\n", solvable2str(pool, s));
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s to
%s\n", solvable2str(pool, s), solvable2str(pool, sd));
+ gotone = 1;
}
- else if (p == SOLVER_SOLUTION_DISTUPGRADE)
+ if (!solv->allowarchchange && s->name == sd->name && s->arch !=
sd->arch && policy_illegal_archchange(solv, s, sd))
{
- s = pool->solvables + rp;
- if (solv->installed && s->repo == solv->installed)
- POOL_DEBUG(SAT_DEBUG_RESULT, "- keep obsolete %s\n",
solvable2str(pool, s));
- else
- POOL_DEBUG(SAT_DEBUG_RESULT, "- install %s from excluded
repository\n", solvable2str(pool, s));
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture change of
%s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
+ gotone = 1;
}
- else
+ if (!solv->allowvendorchange && s->name == sd->name && s->vendor
!= sd->vendor && policy_illegal_vendorchange(solv, s, sd))
{
- /* policy, replace p with rp */
- s = pool->solvables + p;
- sd = rp ? pool->solvables + rp : 0;
- if (s == sd && solv->distupgrade)
- {
- POOL_DEBUG(SAT_DEBUG_RESULT, "- keep obsolete %s\n",
solvable2str(pool, s));
- }
- else if (sd)
- {
- int gotone = 0;
- if (!solv->allowdowngrade && evrcmp(pool, s->evr,
sd->evr, EVRCMP_MATCH_RELEASE) > 0)
- {
- POOL_DEBUG(SAT_DEBUG_RESULT, "- allow downgrade of %s
to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
- gotone = 1;
- }
- if (!solv->allowarchchange && s->name == sd->name &&
s->arch != sd->arch && policy_illegal_archchange(solv, s, sd))
- {
- POOL_DEBUG(SAT_DEBUG_RESULT, "- allow architecture
change of %s to %s\n", solvable2str(pool, s), solvable2str(pool, sd));
- gotone = 1;
- }
- if (!solv->allowvendorchange && s->name == sd->name &&
s->vendor != sd->vendor && policy_illegal_vendorchange(solv, s, sd))
- {
- if (sd->vendor)
- POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change
from '%s' (%s) to '%s' (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s),
id2str(pool, sd->vendor), solvable2str(pool, sd));
- else
- POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change
from '%s' (%s) to no vendor (%s)\n", id2str(pool, s->vendor),
solvable2str(pool, s), solvable2str(pool, sd));
- gotone = 1;
- }
- if (!gotone)
- POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s
with %s\n", solvable2str(pool, s), solvable2str(pool, sd));
- }
+ if (sd->vendor)
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from
'%s' (%s) to '%s' (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s),
id2str(pool, sd->vendor), solvable2str(pool, sd));
else
- {
- POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of
%s\n", solvable2str(pool, s));
- }
-
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- allow vendor change from
'%s' (%s) to no vendor (%s)\n", id2str(pool, s->vendor), solvable2str(pool, s),
solvable2str(pool, sd));
+ gotone = 1;
}
+ if (!gotone)
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- allow replacement of %s with
%s\n", solvable2str(pool, s), solvable2str(pool, sd));
}
- POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
+ else
+ {
+ POOL_DEBUG(SAT_DEBUG_RESULT, "- allow deinstallation of %s\n",
solvable2str(pool, s));
+ }
+
+ }
+ }
+}
+
+void
+solver_printallsolutions(Solver *solv)
+{
+ Pool *pool = solv->pool;
+ int pcnt;
+ Id problem, solution;
+
+ POOL_DEBUG(SAT_DEBUG_RESULT, "Encountered problems! Here are the
solutions:\n\n");
+ pcnt = 0;
+ problem = 0;
+ while ((problem = solver_next_problem(solv, problem)) != 0)
+ {
+ pcnt++;
+ POOL_DEBUG(SAT_DEBUG_RESULT, "Problem %d:\n", pcnt);
+ POOL_DEBUG(SAT_DEBUG_RESULT, "====================================\n");
+ solver_printprobleminfo(solv, problem);
+ POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
+ solution = 0;
+ while ((solution = solver_next_solution(solv, problem, solution)) != 0)
+ {
+ solver_printsolution(solv, problem, solution);
+ POOL_DEBUG(SAT_DEBUG_RESULT, "\n");
}
}
}
diff --git a/src/solverdebug.h b/src/solverdebug.h
index a581d39..8b2feec 100644
--- a/src/solverdebug.h
+++ b/src/solverdebug.h
@@ -25,8 +25,9 @@ extern void solver_printproblem(Solver *solv, Id v);
extern void solver_printwatches(Solver *solv, int type);
extern void solver_printdecisions(Solver *solv);
extern void solver_printtransaction(Solver *solv);
-extern void solver_printprobleminfo(Solver *solv, Queue *job, Id problem);
-extern void solver_printsolutions(Solver *solv, Queue *job);
+extern void solver_printprobleminfo(Solver *solv, Id problem);
+extern void solver_printsolution(Solver *solv, Id problem, Id solution);
+extern void solver_printallsolutions(Solver *solv);
extern void solver_printtrivial(Solver *solv);
extern const char *solver_select2str(Solver *solv, Id select, Id what);

diff --git a/src/transaction.c b/src/transaction.c
index a591258..6047dad 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -678,6 +678,7 @@ struct _TransactionOrderdata {
struct _TransactionElement *tes;
int ntes;
Id *invedgedata;
+ int ninvedgedata;
};

#define TYPE_BROKEN (1<<0)
@@ -702,6 +703,34 @@ transaction_init(Transaction *trans, Pool *pool)
}

void
+transaction_init_clone(Transaction *trans, Transaction *srctrans)
+{
+ memset(trans, 0, sizeof(*trans));
+ trans->pool = srctrans->pool;
+ queue_init_clone(&trans->steps, &srctrans->steps);
+ queue_init_clone(&trans->transaction_info, &srctrans->transaction_info);
+ if (srctrans->transaction_installed)
+ {
+ Repo *installed = srctrans->pool->installed;
+ trans->transaction_installed = sat_calloc(installed->end -
installed->start, sizeof(Id));
+ memcpy(trans->transaction_installed, srctrans->transaction_installed,
(installed->end - installed->start) * sizeof(Id));
+ }
+ map_init_clone(&trans->transactsmap, &srctrans->transactsmap);
+ map_init_clone(&trans->noobsmap, &srctrans->noobsmap);
+ if (srctrans->orderdata)
+ {
+ struct _TransactionOrderdata *od = srctrans->orderdata;
+ trans->orderdata = sat_calloc(1, sizeof(*trans->orderdata));
+ trans->orderdata->tes = sat_malloc2(od->ntes, sizeof(*od->tes));
+ memcpy(trans->orderdata->tes, od->tes, od->ntes * sizeof(*od->tes));
+ trans->orderdata->ntes = od->ntes;
+ trans->orderdata->invedgedata = sat_malloc2(od->ninvedgedata,
sizeof(Id));
+ memcpy(trans->orderdata->invedgedata, od->invedgedata, od->ninvedgedata
* sizeof(Id));
+ trans->orderdata->ninvedgedata = od->ninvedgedata;
+ }
+}
+
+void
transaction_free(Transaction *trans)
{
queue_free(&trans->steps);
@@ -709,6 +738,12 @@ transaction_free(Transaction *trans)
trans->transaction_installed = sat_free(trans->transaction_installed);
map_free(&trans->transactsmap);
map_free(&trans->noobsmap);
+ transaction_free_orderdata(trans);
+}
+
+void
+transaction_free_orderdata(Transaction *trans)
+{
if (trans->orderdata)
{
struct _TransactionOrderdata *od = trans->orderdata;
@@ -1581,6 +1616,7 @@ transaction_order(Transaction *trans, int flags)
for (i = 1, te = od.tes + i; i < numte; i++, te++)
te->edges = te->mark; /* edges now points into invedgedata */
od.edgedata = sat_free(od.edgedata);
+ od.nedgedata = j + 1;

/* now the final ordering */
for (i = 1, te = od.tes + i; i < numte; i++, te++)
@@ -1701,6 +1737,7 @@ printf("free %s [%d]\n", solvid2str(pool, te2->p),
temedianr[od.invedgedata[j]])
trans->orderdata->tes = od.tes;
trans->orderdata->ntes = numte;
trans->orderdata->invedgedata = od.invedgedata;
+ trans->orderdata->ninvedgedata = od.nedgedata;
}
else
{
diff --git a/src/transaction.h b/src/transaction.h
index 5309bab..2738e5c 100644
--- a/src/transaction.h
+++ b/src/transaction.h
@@ -80,7 +80,9 @@ typedef struct _Transaction {
#define SOLVER_TRANSACTION_KEEP_ORDERDATA (1 << 0)

extern void transaction_init(Transaction *trans, struct _Pool *pool);
+extern void transaction_init_clone(Transaction *trans, Transaction *srctrans);
extern void transaction_free(Transaction *trans);
+extern void transaction_free_orderdata(Transaction *trans);
extern void transaction_calculate(Transaction *trans, Queue *decisionq, Map
*noobsmap);

/* if p is installed, returns with pkg(s) obsolete p */
diff --git a/tests/solver/deptestomatic.c b/tests/solver/deptestomatic.c
index 7fea99c..e619661 100644
--- a/tests/solver/deptestomatic.c
+++ b/tests/solver/deptestomatic.c
@@ -1522,7 +1522,7 @@ endElement( void *userData, const char *name )
solver_solve( solv, &pd->trials );
// print result
if (solv->problems.count)
- solver_printsolutions(solv, &pd->trials);
+ solver_printallsolutions(solv);
else
{
if (verbose >= 2)
diff --git a/tests/solver/yps.c b/tests/solver/yps.c
index 48c3b3f..231f6e3 100644
--- a/tests/solver/yps.c
+++ b/tests/solver/yps.c
@@ -458,7 +458,7 @@ main(int argc, char **argv)
solv->solution_callback = solution_callback;
solver_solve(solv, &job);
if (solv->problems.count)
- solver_printsolutions(solv, &job);
+ solver_printallsolutions(solv);
solver_printdecisions(solv);
if (1)
{
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages