dep_selector 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/dep_gecode/dep_selector_swig.i +1 -1
- data/ext/dep_gecode/dep_selector_swig_wrap.cxx +31 -3
- data/ext/dep_gecode/dep_selector_to_gecode.cpp +35 -25
- data/ext/dep_gecode/dep_selector_to_gecode.h +6 -5
- data/ext/dep_gecode/dep_selector_to_gecode_interface.cpp +2 -2
- data/ext/dep_gecode/dep_selector_to_gecode_interface.h +1 -1
- data/lib/dep_selector/dep_selector_version.rb +1 -1
- data/lib/dep_selector/gecode_wrapper.rb +1 -1
- metadata +2 -2
@@ -27,7 +27,7 @@
|
|
27
27
|
|
28
28
|
class VersionProblem;
|
29
29
|
|
30
|
-
VersionProblem * VersionProblemCreate(int packageCount);
|
30
|
+
VersionProblem * VersionProblemCreate(int packageCount, bool dumpStats);
|
31
31
|
void VersionProblemDestroy(VersionProblem * vp);
|
32
32
|
|
33
33
|
int VersionProblemSize(VersionProblem *p);
|
@@ -1633,6 +1633,26 @@ SWIG_AsVal_int (VALUE obj, int *val)
|
|
1633
1633
|
}
|
1634
1634
|
|
1635
1635
|
|
1636
|
+
SWIGINTERN int
|
1637
|
+
SWIG_AsVal_bool (VALUE obj, bool *val)
|
1638
|
+
{
|
1639
|
+
if (obj == Qtrue) {
|
1640
|
+
if (val) *val = true;
|
1641
|
+
return SWIG_OK;
|
1642
|
+
} else if (obj == Qfalse) {
|
1643
|
+
if (val) *val = false;
|
1644
|
+
return SWIG_OK;
|
1645
|
+
} else {
|
1646
|
+
int res = 0;
|
1647
|
+
if (SWIG_AsVal_int (obj, &res) == SWIG_OK) {
|
1648
|
+
if (val) *val = res ? true : false;
|
1649
|
+
return SWIG_OK;
|
1650
|
+
}
|
1651
|
+
}
|
1652
|
+
return SWIG_TypeError;
|
1653
|
+
}
|
1654
|
+
|
1655
|
+
|
1636
1656
|
#define SWIG_From_long LONG2NUM
|
1637
1657
|
|
1638
1658
|
|
@@ -1652,20 +1672,28 @@ SWIG_From_bool (bool value)
|
|
1652
1672
|
SWIGINTERN VALUE
|
1653
1673
|
_wrap_VersionProblemCreate(int argc, VALUE *argv, VALUE self) {
|
1654
1674
|
int arg1 ;
|
1675
|
+
bool arg2 ;
|
1655
1676
|
VersionProblem *result = 0 ;
|
1656
1677
|
int val1 ;
|
1657
1678
|
int ecode1 = 0 ;
|
1679
|
+
bool val2 ;
|
1680
|
+
int ecode2 = 0 ;
|
1658
1681
|
VALUE vresult = Qnil;
|
1659
1682
|
|
1660
|
-
if ((argc <
|
1661
|
-
rb_raise(rb_eArgError, "wrong # of arguments(%d for
|
1683
|
+
if ((argc < 2) || (argc > 2)) {
|
1684
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)",argc); SWIG_fail;
|
1662
1685
|
}
|
1663
1686
|
ecode1 = SWIG_AsVal_int(argv[0], &val1);
|
1664
1687
|
if (!SWIG_IsOK(ecode1)) {
|
1665
1688
|
SWIG_exception_fail(SWIG_ArgError(ecode1), "in method '" "VersionProblemCreate" "', argument " "1"" of type '" "int""'");
|
1666
1689
|
}
|
1667
1690
|
arg1 = static_cast< int >(val1);
|
1668
|
-
|
1691
|
+
ecode2 = SWIG_AsVal_bool(argv[1], &val2);
|
1692
|
+
if (!SWIG_IsOK(ecode2)) {
|
1693
|
+
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "VersionProblemCreate" "', argument " "2"" of type '" "bool""'");
|
1694
|
+
}
|
1695
|
+
arg2 = static_cast< bool >(val2);
|
1696
|
+
result = (VersionProblem *)VersionProblemCreate(arg1,arg2);
|
1669
1697
|
vresult = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_VersionProblem, 0 | 0 );
|
1670
1698
|
return vresult;
|
1671
1699
|
fail:
|
@@ -39,8 +39,9 @@ const int VersionProblem::MIN_TRUST_LEVEL = 0;
|
|
39
39
|
const int VersionProblem::MAX_TRUST_LEVEL = 10;
|
40
40
|
const int VersionProblem::MAX_PREFERRED_WEIGHT = 10;
|
41
41
|
|
42
|
-
VersionProblem::VersionProblem(int packageCount)
|
43
|
-
: size(packageCount),
|
42
|
+
VersionProblem::VersionProblem(int packageCount, bool dumpStats)
|
43
|
+
: size(packageCount), version_constraint_count(0), dump_stats(dumpStats),
|
44
|
+
finalized(false), cur_package(0), package_versions(*this, packageCount),
|
44
45
|
disabled_package_variables(*this, packageCount, 0, 1), total_disabled(*this, 0, packageCount*MAX_TRUST_LEVEL),
|
45
46
|
total_required_disabled(*this, 0, packageCount), total_induced_disabled(*this, 0, packageCount),
|
46
47
|
total_suspicious_disabled(*this, 0, packageCount),
|
@@ -61,8 +62,9 @@ VersionProblem::VersionProblem(int packageCount)
|
|
61
62
|
}
|
62
63
|
|
63
64
|
VersionProblem::VersionProblem(bool share, VersionProblem & s)
|
64
|
-
: Space(share, s),
|
65
|
-
|
65
|
+
: Space(share, s),
|
66
|
+
size(s.size), version_constraint_count(s.version_constraint_count), dump_stats(s.dump_stats),
|
67
|
+
finalized(s.finalized), cur_package(s.cur_package),
|
66
68
|
disabled_package_variables(s.disabled_package_variables), total_disabled(s.total_disabled),
|
67
69
|
total_required_disabled(s.total_required_disabled), total_induced_disabled(s.total_induced_disabled),
|
68
70
|
total_suspicious_disabled(s.total_suspicious_disabled),
|
@@ -135,7 +137,8 @@ VersionProblem::AddVersionConstraint(int packageId, int version,
|
|
135
137
|
BoolVar version_match(*this, 0, 1);
|
136
138
|
BoolVar depend_match(*this, 0, 1);
|
137
139
|
BoolVar predicated_depend_match(*this, 0, 1);
|
138
|
-
|
140
|
+
|
141
|
+
version_constraint_count++;
|
139
142
|
#ifdef DEBUG
|
140
143
|
std::cout << "Add VC for " << packageId << " @ " << version << " depPkg " << dependentPackageId;
|
141
144
|
std::cout << " [ " << minDependentVersion << ", " << maxDependentVersion << " ]" << std::endl;
|
@@ -489,32 +492,39 @@ VersionProblem * VersionProblem::Solve(VersionProblem * problem)
|
|
489
492
|
VersionProblem *best_solution = NULL;
|
490
493
|
timer.start();
|
491
494
|
|
492
|
-
|
493
|
-
|
495
|
+
Restart<VersionProblem> solver(problem);
|
496
|
+
best_solution = NULL;
|
494
497
|
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
}
|
504
|
-
best_solution = solution;
|
505
|
-
++i;
|
498
|
+
while (VersionProblem *solution = solver.next())
|
499
|
+
{
|
500
|
+
if (best_solution != NULL)
|
501
|
+
{
|
502
|
+
delete best_solution;
|
503
|
+
}
|
504
|
+
best_solution = solution;
|
505
|
+
++i;
|
506
506
|
#ifdef DEBUG
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
507
|
+
std::cout << "Trial Solution #" << i << "===============================" << std::endl;
|
508
|
+
const Search::Statistics & stats = solver.statistics();
|
509
|
+
std::cout << "Solver stats: Prop:" << stats.propagate << " Fail:" << stats.fail << " Node:" << stats.node;
|
510
|
+
std::cout << " Depth:" << stats.depth << " memory:" << stats.memory << std::endl;
|
511
|
+
solution->Print(std::cout);
|
512
512
|
#endif //DEBUG
|
513
|
-
}
|
514
|
-
|
515
513
|
}
|
516
514
|
|
517
515
|
double elapsed_time = timer.stop();
|
516
|
+
|
517
|
+
if (problem->dump_stats) {
|
518
|
+
std::cerr << "dep_selector solve: ";
|
519
|
+
std::cerr << (best_solution ? "SOLVED" : "FAILED") << " ";
|
520
|
+
std::cerr << problem->size << " packages, " << problem->version_constraint_count << " constraints, ";
|
521
|
+
std::cerr << "Time: " << elapsed_time << "ms ";
|
522
|
+
const Search::Statistics & final_stats = solver.statistics();
|
523
|
+
std::cerr << "Stats: " << i << " steps, " << final_stats.memory << " bytes, ";
|
524
|
+
std::cerr << final_stats.propagate << " props, " << final_stats.node << " nodes, " << final_stats.depth << " depth ";
|
525
|
+
std::cerr << std::endl << std::flush;
|
526
|
+
}
|
527
|
+
|
518
528
|
#ifdef DEBUG_LITE
|
519
529
|
std::cout << "Solution completed: " << (best_solution ? "Found solution" : "No solution found") << std::endl;
|
520
530
|
std::cout << "Solution consumed: " << elapsed_time << " ms " << i << " steps" << std::endl;
|
@@ -42,13 +42,13 @@ using namespace Gecode;
|
|
42
42
|
|
43
43
|
class VersionProblem : public Space
|
44
44
|
{
|
45
|
-
|
45
|
+
public:
|
46
46
|
static const int UNRESOLVED_VARIABLE;
|
47
47
|
static const int MIN_TRUST_LEVEL;
|
48
48
|
static const int MAX_TRUST_LEVEL;
|
49
49
|
static const int MAX_PREFERRED_WEIGHT;
|
50
50
|
|
51
|
-
VersionProblem(int packageCount);
|
51
|
+
VersionProblem(int packageCount, bool dumpStats = true);
|
52
52
|
// Clone constructor; check gecode rules for this...
|
53
53
|
VersionProblem(bool share, VersionProblem & s);
|
54
54
|
virtual ~VersionProblem();
|
@@ -95,10 +95,11 @@ class VersionProblem : public Space
|
|
95
95
|
|
96
96
|
protected:
|
97
97
|
int size;
|
98
|
+
int version_constraint_count;
|
98
99
|
int cur_package;
|
99
|
-
bool
|
100
|
+
bool dump_stats;
|
100
101
|
bool finalized;
|
101
|
-
|
102
|
+
|
102
103
|
BoolVarArgs version_flags;
|
103
104
|
IntVarArray package_versions;
|
104
105
|
BoolVarArray disabled_package_variables;
|
@@ -112,11 +113,11 @@ class VersionProblem : public Space
|
|
112
113
|
IntVar total_preferred_at_latest;
|
113
114
|
IntVar total_not_preferred_at_latest;
|
114
115
|
|
115
|
-
int * disabled_package_weights;
|
116
116
|
int * preferred_at_latest_weights;
|
117
117
|
int * is_required;
|
118
118
|
int * is_suspicious;
|
119
119
|
|
120
|
+
bool CheckPackageId(int id);
|
120
121
|
void AddPackagesPreferredToBeAtLatestObjectiveFunction(const VersionProblem & best_known_solution);
|
121
122
|
void ConstrainVectorLessThanBest(IntVarArgs & current, IntVarArgs & best);
|
122
123
|
void BuildCostVector(IntVarArgs & costVector) const;
|
@@ -29,9 +29,9 @@
|
|
29
29
|
// insure proper memory behaviour
|
30
30
|
|
31
31
|
// FFI friendly
|
32
|
-
VersionProblem * VersionProblemCreate(int packageCount)
|
32
|
+
VersionProblem * VersionProblemCreate(int packageCount, bool dump_stats)
|
33
33
|
{
|
34
|
-
|
34
|
+
return new VersionProblem(packageCount, dump_stats);
|
35
35
|
}
|
36
36
|
|
37
37
|
void VersionProblemDestroy(VersionProblem * p)
|
@@ -31,7 +31,7 @@ extern "C" {
|
|
31
31
|
typedef struct VersionProblem VersionProblem;
|
32
32
|
#endif // __cplusplus
|
33
33
|
|
34
|
-
VersionProblem * VersionProblemCreate(int packageCount);
|
34
|
+
VersionProblem * VersionProblemCreate(int packageCount, bool dumpStats);
|
35
35
|
void VersionProblemDestroy(VersionProblem * vp);
|
36
36
|
|
37
37
|
|
@@ -30,7 +30,7 @@ module DepSelector
|
|
30
30
|
# modeled after http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/
|
31
31
|
def initialize(problem_or_package_count)
|
32
32
|
if (problem_or_package_count.is_a?(Numeric))
|
33
|
-
@gecode_problem = Dep_gecode.VersionProblemCreate(problem_or_package_count)
|
33
|
+
@gecode_problem = Dep_gecode.VersionProblemCreate(problem_or_package_count, true)
|
34
34
|
else
|
35
35
|
@gecode_problem = problem_or_package_count
|
36
36
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dep_selector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Christopher Walters
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-03-
|
14
|
+
date: 2011-03-30 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|