dep_selector 0.0.4 → 0.0.5
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.
@@ -29,6 +29,8 @@
|
|
29
29
|
#include <iostream>
|
30
30
|
#include <vector>
|
31
31
|
|
32
|
+
|
33
|
+
//#define MEMORY_DEBUG
|
32
34
|
//#define DEBUG
|
33
35
|
//#define USE_DUMB_BRANCHING
|
34
36
|
#define VECTOR_CONSTRAIN
|
@@ -39,6 +41,64 @@ const int VersionProblem::MIN_TRUST_LEVEL = 0;
|
|
39
41
|
const int VersionProblem::MAX_TRUST_LEVEL = 10;
|
40
42
|
const int VersionProblem::MAX_PREFERRED_WEIGHT = 10;
|
41
43
|
|
44
|
+
VersionProblemPool::VersionProblemPool() : elems()
|
45
|
+
{ }
|
46
|
+
|
47
|
+
VersionProblemPool::~VersionProblemPool()
|
48
|
+
{
|
49
|
+
DeleteAll();
|
50
|
+
}
|
51
|
+
void VersionProblemPool::Add(VersionProblem * vp)
|
52
|
+
{
|
53
|
+
vp->pool = this;
|
54
|
+
#ifdef MEMORY_DEBUG
|
55
|
+
std::cout << "Pool add\t" << vp << std::endl << std::flush;
|
56
|
+
#endif // MEMORY_DEBUG
|
57
|
+
elems.insert(vp);
|
58
|
+
}
|
59
|
+
void VersionProblemPool::Delete(VersionProblem *vp)
|
60
|
+
{
|
61
|
+
if (vp->pool != 0)
|
62
|
+
{
|
63
|
+
#ifdef MEMORY_DEBUG
|
64
|
+
std::cout << "Pool del\t" << vp << std::endl << std::flush;
|
65
|
+
#endif // MEMORY_DEBUG
|
66
|
+
elems.erase(vp);
|
67
|
+
vp->pool = 0;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
void VersionProblemPool::ShowAll()
|
71
|
+
{
|
72
|
+
std::cout << "ShowAll =====================================================" << std::endl << std::flush;
|
73
|
+
std::set<VersionProblem *>::iterator i;
|
74
|
+
for(i = elems.begin(); i != elems.end(); i++) {
|
75
|
+
#ifdef MEMORY_DEBUG
|
76
|
+
std::cout << "ShowAll has\t\t\t" << *i << std::endl << std::flush;
|
77
|
+
#endif // MEMORY_DEBUG
|
78
|
+
}
|
79
|
+
std::cout << "ShowAll =====================================================" << std::endl << std::flush;
|
80
|
+
}
|
81
|
+
|
82
|
+
void VersionProblemPool::DeleteAll()
|
83
|
+
{
|
84
|
+
#ifdef MEMORY_DEBUG
|
85
|
+
ShowAll();
|
86
|
+
#endif
|
87
|
+
std::set<VersionProblem *>::iterator i;
|
88
|
+
for(i = elems.begin(); i != elems.end(); i++) {
|
89
|
+
VersionProblem *vp = *i;
|
90
|
+
vp->pool = 0;
|
91
|
+
delete *i;
|
92
|
+
}
|
93
|
+
elems.clear();
|
94
|
+
#ifdef MEMORY_DEBUG
|
95
|
+
std::cout << "DeleteAll ===================================================" << std::endl << std::flush;
|
96
|
+
#endif
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
42
102
|
VersionProblem::VersionProblem(int packageCount, bool dumpStats)
|
43
103
|
: size(packageCount), version_constraint_count(0), dump_stats(dumpStats),
|
44
104
|
finalized(false), cur_package(0), package_versions(*this, packageCount),
|
@@ -51,7 +111,8 @@ VersionProblem::VersionProblem(int packageCount, bool dumpStats)
|
|
51
111
|
// These domains could be narrowed a bit; check later
|
52
112
|
total_preferred_at_latest(*this, -packageCount*MAX_PREFERRED_WEIGHT, packageCount*MAX_PREFERRED_WEIGHT),
|
53
113
|
total_not_preferred_at_latest(*this, -packageCount, packageCount),
|
54
|
-
preferred_at_latest_weights(new int[packageCount])
|
114
|
+
preferred_at_latest_weights(new int[packageCount]),
|
115
|
+
pool(0)
|
55
116
|
{
|
56
117
|
for (int i = 0; i < packageCount; i++)
|
57
118
|
{
|
@@ -59,6 +120,7 @@ VersionProblem::VersionProblem(int packageCount, bool dumpStats)
|
|
59
120
|
is_required[i] = 0;
|
60
121
|
is_suspicious[i] = 0;
|
61
122
|
}
|
123
|
+
// std::cout << "C VersionProblem(int,bool)\t" << this << std::endl << std::flush;
|
62
124
|
}
|
63
125
|
|
64
126
|
VersionProblem::VersionProblem(bool share, VersionProblem & s)
|
@@ -72,7 +134,8 @@ VersionProblem::VersionProblem(bool share, VersionProblem & s)
|
|
72
134
|
at_latest(s.at_latest),
|
73
135
|
total_preferred_at_latest(s.total_preferred_at_latest),
|
74
136
|
total_not_preferred_at_latest(s.total_preferred_at_latest),
|
75
|
-
preferred_at_latest_weights(NULL)
|
137
|
+
preferred_at_latest_weights(NULL),
|
138
|
+
pool(s.pool)
|
76
139
|
{
|
77
140
|
package_versions.update(*this, share, s.package_versions);
|
78
141
|
disabled_package_variables.update(*this, share, s.disabled_package_variables);
|
@@ -83,6 +146,11 @@ VersionProblem::VersionProblem(bool share, VersionProblem & s)
|
|
83
146
|
at_latest.update(*this, share, s.at_latest);
|
84
147
|
total_preferred_at_latest.update(*this, share, s.total_preferred_at_latest);
|
85
148
|
total_not_preferred_at_latest.update(*this, share, s.total_not_preferred_at_latest);
|
149
|
+
|
150
|
+
pool->Add(this);
|
151
|
+
#ifdef MEMORY_DEBUG
|
152
|
+
std::cout << "C VersionProblem(bool, VP)\t" << this << std::endl << std::flush;
|
153
|
+
#endif
|
86
154
|
}
|
87
155
|
|
88
156
|
// Support for gecode
|
@@ -96,6 +164,12 @@ VersionProblem::~VersionProblem()
|
|
96
164
|
delete[] preferred_at_latest_weights;
|
97
165
|
delete[] is_required;
|
98
166
|
delete[] is_suspicious;
|
167
|
+
if (pool!= 0) {
|
168
|
+
pool->Delete(this);
|
169
|
+
}
|
170
|
+
#ifdef MEMORY_DEBUG
|
171
|
+
std::cout << "D VersionProblem\t\t" << this << std::endl << std::flush;
|
172
|
+
#endif
|
99
173
|
}
|
100
174
|
|
101
175
|
int VersionProblem::Size()
|
@@ -478,59 +552,84 @@ void VersionProblem::ConstrainVectorLessThanBest(IntVarArgs & current, IntVarArg
|
|
478
552
|
rel(*this, borrow[current.size()], IRT_EQ, 1);
|
479
553
|
}
|
480
554
|
|
481
|
-
VersionProblem * VersionProblem::
|
555
|
+
VersionProblem * VersionProblem::InnerSolve(VersionProblem * problem, int &itercount)
|
482
556
|
{
|
483
|
-
|
484
|
-
|
485
|
-
#ifdef DEBUG
|
486
|
-
std::cout << "Before solve" << std::endl;
|
487
|
-
problem->Print(std::cout);
|
488
|
-
#endif //DEBUG
|
489
|
-
int i = 0;
|
490
|
-
|
491
|
-
Gecode::Support::Timer timer;
|
492
|
-
VersionProblem *best_solution = NULL;
|
493
|
-
timer.start();
|
557
|
+
Gecode::Support::Timer timer;
|
558
|
+
timer.start();
|
494
559
|
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
560
|
+
#ifdef MEMORY_DEBUG
|
561
|
+
std::cout << "Creating solver" << std::endl << std::flush;
|
562
|
+
#endif
|
563
|
+
VersionProblem *best_solution = NULL;
|
564
|
+
Restart<VersionProblem> solver(problem);
|
565
|
+
|
566
|
+
#ifdef MEMORY_DEBUG
|
567
|
+
std::cout << "Starting Solve" << std::endl << std::flush;
|
568
|
+
#endif
|
569
|
+
|
570
|
+
while (VersionProblem *solution = solver.next())
|
499
571
|
{
|
500
|
-
|
572
|
+
#ifdef MEMORY_DEBUG
|
573
|
+
std::cout << "Solver Next " << solution << std::endl << std::flush;
|
574
|
+
#endif
|
575
|
+
if (best_solution != NULL)
|
501
576
|
{
|
502
|
-
|
577
|
+
delete best_solution;
|
503
578
|
}
|
504
|
-
|
505
|
-
|
579
|
+
best_solution = solution;
|
580
|
+
++itercount;
|
506
581
|
#ifdef DEBUG
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
#endif //DEBUG
|
513
|
-
|
582
|
+
std::cout << "Trial Solution #" << itercount << "===============================" << std::endl;
|
583
|
+
const Search::Statistics & stats = solver.statistics();
|
584
|
+
std::cout << "Solver stats: Prop:" << stats.propagate << " Fail:" << stats.fail << " Node:" << stats.node;
|
585
|
+
std::cout << " Depth:" << stats.depth << " memory:" << stats.memory << std::endl;
|
586
|
+
solution->Print(std::cout);
|
587
|
+
#endif //DEBUG
|
588
|
+
}
|
514
589
|
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
590
|
+
double elapsed_time = timer.stop();
|
591
|
+
|
592
|
+
if (problem->dump_stats) {
|
593
|
+
std::cerr << "dep_selector solve: ";
|
594
|
+
std::cerr << (best_solution ? "SOLVED" : "FAILED") << " ";
|
595
|
+
std::cerr << problem->size << " packages, " << problem->version_constraint_count << " constraints, ";
|
596
|
+
std::cerr << "Time: " << elapsed_time << "ms ";
|
597
|
+
const Search::Statistics & final_stats = solver.statistics();
|
598
|
+
std::cerr << "Stats: " << itercount << " steps, ";
|
599
|
+
std::cerr << final_stats.memory << " bytes, ";
|
600
|
+
std::cerr << final_stats.propagate << " props, " << final_stats.node << " nodes, " << final_stats.depth << " depth ";
|
601
|
+
std::cerr << std::endl << std::flush;
|
602
|
+
}
|
603
|
+
|
604
|
+
return best_solution;
|
605
|
+
}
|
527
606
|
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
607
|
+
VersionProblem * VersionProblem::Solve(VersionProblem * problem)
|
608
|
+
{
|
609
|
+
|
610
|
+
problem->Finalize();
|
611
|
+
problem->status();
|
612
|
+
|
613
|
+
VersionProblemPool *pool = new VersionProblemPool();
|
614
|
+
problem->pool = pool;
|
615
|
+
|
616
|
+
#ifdef DEBUG
|
617
|
+
std::cout << "Before solve" << std::endl;
|
618
|
+
problem->Print(std::cout);
|
619
|
+
#endif //DEB UG
|
620
|
+
int itercount = 0;
|
621
|
+
|
622
|
+
VersionProblem *best_solution = InnerSolve(problem, itercount);
|
623
|
+
|
624
|
+
#ifdef MEMORY_DEBUG
|
625
|
+
std::cout << "Solver Best Solution " << best_solution << std::endl << std::flush;
|
626
|
+
#endif
|
627
|
+
|
628
|
+
pool->Delete(best_solution);
|
629
|
+
problem->pool = 0;
|
630
|
+
|
631
|
+
pool->DeleteAll();
|
632
|
+
delete pool;
|
534
633
|
|
535
634
|
return best_solution;
|
536
635
|
}
|
@@ -23,6 +23,7 @@
|
|
23
23
|
#include "dep_selector_to_gecode_interface.h"
|
24
24
|
#include <iostream>
|
25
25
|
#include <vector>
|
26
|
+
#include <set>
|
26
27
|
|
27
28
|
#include <gecode/driver.hh>
|
28
29
|
#include <gecode/int.hh>
|
@@ -40,6 +41,19 @@ using namespace Gecode;
|
|
40
41
|
// Add optimization functions
|
41
42
|
// Allow non-contiguous ranges in package dependencies.
|
42
43
|
|
44
|
+
// TODO: Add locking
|
45
|
+
struct VersionProblemPool
|
46
|
+
{
|
47
|
+
std::set<VersionProblem *> elems;
|
48
|
+
VersionProblemPool();
|
49
|
+
~VersionProblemPool();
|
50
|
+
void Add(VersionProblem * vp);
|
51
|
+
void Delete(VersionProblem *vp);
|
52
|
+
void ShowAll();
|
53
|
+
void DeleteAll();
|
54
|
+
};
|
55
|
+
|
56
|
+
|
43
57
|
class VersionProblem : public Space
|
44
58
|
{
|
45
59
|
public:
|
@@ -90,6 +104,7 @@ public:
|
|
90
104
|
void Print(std::ostream &out);
|
91
105
|
void PrintPackageVar(std::ostream & out, int packageId) ;
|
92
106
|
|
107
|
+
static VersionProblem *InnerSolve(VersionProblem * problem, int & itercount);
|
93
108
|
static VersionProblem *Solve(VersionProblem *problem);
|
94
109
|
|
95
110
|
|
@@ -117,10 +132,14 @@ public:
|
|
117
132
|
int * is_required;
|
118
133
|
int * is_suspicious;
|
119
134
|
|
135
|
+
VersionProblemPool *pool;
|
136
|
+
|
120
137
|
bool CheckPackageId(int id);
|
121
138
|
void AddPackagesPreferredToBeAtLatestObjectiveFunction(const VersionProblem & best_known_solution);
|
122
139
|
void ConstrainVectorLessThanBest(IntVarArgs & current, IntVarArgs & best);
|
123
140
|
void BuildCostVector(IntVarArgs & costVector) const;
|
141
|
+
|
142
|
+
friend class VersionProblemPool;
|
124
143
|
};
|
125
144
|
|
126
145
|
template<class T> void PrintVarAligned(const char * message, T & var);
|
data/ext/dep_gecode/extconf.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dep_selector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
6
10
|
platform: ruby
|
7
11
|
authors:
|
8
12
|
- Christopher Walters
|
@@ -11,7 +15,7 @@ autorequire:
|
|
11
15
|
bindir: bin
|
12
16
|
cert_chain: []
|
13
17
|
|
14
|
-
date: 2011-
|
18
|
+
date: 2011-04-01 00:00:00 -07:00
|
15
19
|
default_executable:
|
16
20
|
dependencies: []
|
17
21
|
|
@@ -49,7 +53,7 @@ files:
|
|
49
53
|
- ext/dep_gecode/dep_selector_to_gecode_interface.cpp
|
50
54
|
- ext/dep_gecode/extconf.rb
|
51
55
|
- ext/dep_gecode/lib/dep_selector_to_gecode.rb
|
52
|
-
has_rdoc:
|
56
|
+
has_rdoc: false
|
53
57
|
homepage: http://github.com/algorist/dep_selector
|
54
58
|
licenses:
|
55
59
|
- Apache v2
|
@@ -59,22 +63,24 @@ rdoc_options: []
|
|
59
63
|
require_paths:
|
60
64
|
- lib
|
61
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
66
|
requirements:
|
64
67
|
- - ">="
|
65
68
|
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
66
71
|
version: "0"
|
67
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
73
|
requirements:
|
70
74
|
- - ">="
|
71
75
|
- !ruby/object:Gem::Version
|
76
|
+
segments:
|
77
|
+
- 0
|
72
78
|
version: "0"
|
73
79
|
requirements:
|
74
80
|
- gecode, version 3.5 or greater
|
75
81
|
- g++
|
76
82
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.6
|
83
|
+
rubygems_version: 1.3.6
|
78
84
|
signing_key:
|
79
85
|
specification_version: 3
|
80
86
|
summary: Given packages, versions, and a dependency graph, find a valid assignment of package versions
|