Author: kkaempf
Date: Thu Nov 1 15:18:46 2007
New Revision: 7734
URL: http://svn.opensuse.org/viewcvs/zypp?rev=7734&view=rev
Log:
First try on a (ruby based) policy engine
- src/policy.h: generic policy interface
- src/policy-ruby.c: ruby implementation of policy interface
- testsuite/satsolver_policy.rb: sample policy as ruby code
Added:
trunk/sat-solver/src/policy-ruby.c
trunk/sat-solver/src/policy.h
trunk/sat-solver/testsuite/satsolver_policy.rb
Modified:
trunk/sat-solver/ (props changed)
trunk/sat-solver/CMakeLists.txt
trunk/sat-solver/src/CMakeLists.txt
trunk/sat-solver/src/solver.c
trunk/sat-solver/testsuite/CMakeLists.txt
Modified: trunk/sat-solver/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/CMakeLists.txt?rev=7734&r1=7733&r2=7734&view=diff
==============================================================================
--- trunk/sat-solver/CMakeLists.txt (original)
+++ trunk/sat-solver/CMakeLists.txt Thu Nov 1 15:18:46 2007
@@ -22,6 +22,7 @@
FIND_PACKAGE(Db43 REQUIRED)
FIND_PACKAGE(EXPAT REQUIRED)
+FIND_PACKAGE(Ruby REQUIRED)
SET( PACKAGE "satsolver" )
SET( VERSION "${LIBSATSOLVER_MAJOR}.${LIBSATSOLVER_MINOR}.${LIBSATSOLVER_PATCH}" )
Modified: trunk/sat-solver/src/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/CMakeLists.txt?rev=7734&r1=7733&r2=7734&view=diff
==============================================================================
--- trunk/sat-solver/src/CMakeLists.txt (original)
+++ trunk/sat-solver/src/CMakeLists.txt Thu Nov 1 15:18:46 2007
@@ -1,10 +1,13 @@
SET(libsatsolver_SRCS bitmap.c poolarch.c poolvendor.c poolid.c
-solver.c repo_solv.c evr.c pool.c queue.c repo.c util.c)
+solver.c repo_solv.c evr.c pool.c queue.c repo.c util.c
+policy-ruby.c)
ADD_LIBRARY(satsolver STATIC ${libsatsolver_SRCS})
-SET(libsatsolver_HEADERS bitmap.h evr.h hash.h poolarch.h poolvendor.h pool.h poolid.h pooltypes.h queue.h solvable.h solver.h repo.h repo_solv.h util.h )
+SET(libsatsolver_HEADERS bitmap.h evr.h hash.h policy.h poolarch.h poolvendor.h pool.h poolid.h pooltypes.h queue.h solvable.h solver.h repo.h repo_solv.h util.h )
+
+SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O3 -Wall -I${RUBY_INCLUDE_PATH}" )
INSTALL( FILES ${libsatsolver_HEADERS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/satsolver" )
INSTALL(TARGETS satsolver LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
Added: trunk/sat-solver/src/policy-ruby.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/policy-ruby.c?rev=7734&view=auto
==============================================================================
--- trunk/sat-solver/src/policy-ruby.c (added)
+++ trunk/sat-solver/src/policy-ruby.c Thu Nov 1 15:18:46 2007
@@ -0,0 +1,62 @@
+/*
+ * Ruby policy backend for SAT solver
+ *
+ */
+#include
+#include "policy.h"
+
+#include "ruby.h"
+
+static const Pool *pool;
+static VALUE cPolicy;
+
+int
+policy_init( const Pool *p )
+{
+ ruby_init();
+ ruby_init_loadpath();
+ rb_set_safe_level(0); //FIXME
+
+ /* give the ruby code a name */
+ ruby_script("satsolver_policy");
+
+ cPolicy = rb_define_class( "SatPolicy", rb_cObject );
+
+ /* load the policy implementation */
+ rb_require( "satsolver_policy" );
+
+ pool = p;
+
+ return 0;
+}
+
+
+int
+policy_exit( void )
+{
+ pool = NULL;
+ return 0;
+}
+
+/*-----------------------------------------------*/
+int
+policy_printrules( void )
+{
+ static VALUE id = Qnil;
+
+ /* check if ruby implementation available */
+ if (NIL_P( id )) {
+ id = rb_intern( "printrules" );
+ if (rb_respond_to( cPolicy, id ) == Qfalse) {
+ id = Qfalse;
+ }
+ }
+
+ /* call ruby, if available */
+ if (RTEST( id )) {
+ return RTEST( rb_funcall( cPolicy, id, 0 ) );
+ }
+
+ /* default: false */
+ return 0;
+}
Added: trunk/sat-solver/src/policy.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/policy.h?rev=7734&view=auto
==============================================================================
--- trunk/sat-solver/src/policy.h (added)
+++ trunk/sat-solver/src/policy.h Thu Nov 1 15:18:46 2007
@@ -0,0 +1,11 @@
+/*
+ * Generic policy interface for SAT solver
+ *
+ */
+
+#include "solver.h"
+
+int policy_printrules( void );
+
+int policy_init( const Pool *pool );
+int policy_exit( void );
Modified: trunk/sat-solver/src/solver.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/src/solver.c?rev=7734&r1=7733&r2=7734&view=diff
==============================================================================
--- trunk/sat-solver/src/solver.c (original)
+++ trunk/sat-solver/src/solver.c Thu Nov 1 15:18:46 2007
@@ -16,6 +16,8 @@
#include "evr.h"
#include "poolvendor.h"
+#include "policy.h"
+
#define RULES_BLOCK 63
static Pool *prune_best_version_arch_sortcmp_data;
@@ -1872,6 +1874,8 @@
memset(solv->rules, 0, sizeof(Rule));
solv->nrules = 1;
+ policy_init( pool );
+
return solv;
}
@@ -1883,6 +1887,8 @@
void
solver_free(Solver *solv)
{
+ policy_exit();
+
queue_free(&solv->ruletojob);
queue_free(&solv->decisionq);
queue_free(&solv->decisionq_why);
@@ -1924,16 +1930,15 @@
Pool *pool = solv->pool;
Id p, *dp;
-#if 0
- printf("number of rules: %d\n", solv->nrules);
+if (policy_printrules())
{
+ printf("number of rules: %d\n", solv->nrules);
int i;
for (i = 0; i < solv->nrules; i++)
{
printrule(solv, solv->rules + i);
}
}
-#endif
/* all new rules are learnt after this point */
solv->learntrules = solv->nrules;
@@ -2973,8 +2978,7 @@
FOR_PROVIDES(p, pp, sug)
MAPSET(&solv->suggestsmap, p);
}
- }
- }
+ } }
for (i = 1; i < pool->nsolvables; i++)
{
if (solv->decisionmap[i] != 0)
Modified: trunk/sat-solver/testsuite/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/testsuite/CMakeLists.txt?rev=7734&r1=7733&r2=7734&view=diff
==============================================================================
--- trunk/sat-solver/testsuite/CMakeLists.txt (original)
+++ trunk/sat-solver/testsuite/CMakeLists.txt Thu Nov 1 15:18:46 2007
@@ -1,14 +1,13 @@
SET(yps_SOURCES yps.c)
ADD_EXECUTABLE(yps ${yps_SOURCES})
-TARGET_LINK_LIBRARIES(yps satsolver)
+TARGET_LINK_LIBRARIES(yps satsolver ${RUBY_LIBRARY})
SET(gimmick_SOURCES gimmick.c)
ADD_EXECUTABLE(gimmick ${gimmick_SOURCES})
-TARGET_LINK_LIBRARIES(gimmick satsolver)
+TARGET_LINK_LIBRARIES(gimmick satsolver ${RUBY_LIBRARY})
SET(deptestomatic_SOURCES deptestomatic.c)
ADD_EXECUTABLE(deptestomatic ${deptestomatic_SOURCES})
-TARGET_LINK_LIBRARIES(deptestomatic satsolver ${EXPAT_LIBRARY})
-
+TARGET_LINK_LIBRARIES(deptestomatic satsolver ${EXPAT_LIBRARY} ${RUBY_LIBRARY})
Added: trunk/sat-solver/testsuite/satsolver_policy.rb
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/testsuite/satsolver_policy.rb?rev=7734&view=auto
==============================================================================
--- trunk/sat-solver/testsuite/satsolver_policy.rb (added)
+++ trunk/sat-solver/testsuite/satsolver_policy.rb Thu Nov 1 15:18:46 2007
@@ -0,0 +1,16 @@
+#
+# Sat solver policy class
+#
+# Implements policies as singleton methods
+#
+
+class SatPolicy
+ #
+ # print rules before solving ?
+ #
+ #
+ def self.printrules
+ STDERR.puts "printrules?"
+ return true
+ end
+end
\ No newline at end of file
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org