Skip to content

Commit 4dd5e72

Browse files
committed
Some notions were confused. Also, better peformance now
1 parent d976a6a commit 4dd5e72

File tree

7 files changed

+34
-40
lines changed

7 files changed

+34
-40
lines changed

src/arjun.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ set_get_macro(bool, distill)
224224
set_get_macro(bool, intree)
225225
set_get_macro(bool, bve_pre_simplify)
226226
set_get_macro(bool, simp)
227-
set_get_macro(uint32_t, incidence_sort)
227+
set_get_macro(uint32_t, unknown_sort)
228+
set_get_macro(uint32_t, incidence_count)
228229
set_get_macro(bool, or_gate_based)
229230
set_get_macro(bool, xor_gates_based)
230231
set_get_macro(bool, probe_based)

src/arjun.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ namespace ArjunNS {
9292
void set_intree(bool intree);
9393
void set_simp(bool simp);
9494
void set_bve_pre_simplify(bool bve_pre_simp);
95-
void set_incidence_sort(uint32_t incidence_sort);
95+
void set_unknown_sort(uint32_t unknown_sort);
96+
void set_incidence_count(uint32_t incidence_count);
9697
void set_or_gate_based(bool or_gate_based);
9798
void set_xor_gates_based(bool xor_gates_based);
9899
void set_probe_based(bool probe_based);
@@ -121,7 +122,8 @@ namespace ArjunNS {
121122
bool get_distill() const;
122123
bool get_intree() const;
123124
bool get_bve_pre_simplify() const;
124-
uint32_t get_incidence_sort() const;
125+
uint32_t get_incidence_count() const;
126+
uint32_t get_unknown_sort() const;
125127
bool get_or_gate_based() const;
126128
bool get_xor_gates_based() const;
127129
bool get_probe_based() const;

src/common.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ void Common::get_incidence()
212212
assert(inc.size() == orig_num_vars*2);
213213
for(uint32_t i = 0; i < orig_num_vars; i++) {
214214
Lit l = Lit(i, true);
215-
if (conf.incidence_sort == 10) {
215+
if (conf.incidence_count == 1) {
216216
incidence[l.var()] = inc[l.toInt()] + inc[(~l).toInt()];
217-
} else if (conf.incidence_sort == 11) {
217+
} else if (conf.incidence_count == 2) {
218218
incidence[l.var()] = std::max(inc[l.toInt()], inc[(~l).toInt()]);
219-
} else {
219+
} else if (conf.incidence_count == 3) {
220220
incidence[l.var()] = std::min(inc[l.toInt()],inc[(~l).toInt()]);
221221
}
222222
}
@@ -290,14 +290,7 @@ bool Common::preproc_and_duplicate()
290290
seen.resize(solver->nVars(), 0);
291291

292292
get_incidence();
293-
if (conf.incidence_sort == 4 || conf.incidence_sort == 5) {
294-
#ifdef LOUVAIN_COMMS
295-
calc_community_parts();
296-
#else
297-
cout << "ERROR: you must compile with louvain community libraries for this to work. Install https://github.com/meelgroup/louvain-community first." << endl;
298-
exit(-1);
299-
#endif
300-
}
293+
calc_community_parts();
301294
if (conf.simp && !simplify()) return false;
302295
get_incidence();
303296
duplicate_problem();
@@ -315,13 +308,18 @@ bool Common::preproc_and_duplicate()
315308
return true;
316309
}
317310

318-
#ifdef LOUVAIN_COMMS
319311
void Common::calc_community_parts()
320312
{
321-
double myTime = cpuTime();
322-
if (conf.verb) {
323-
cout << "c [arjun] Calculating Louvain Communities..." << endl;
313+
if (!(conf.unknown_sort == 4 || conf.unknown_sort == 5)) {
314+
return;
324315
}
316+
#ifndef LOUVAIN_COMMS
317+
cout << "ERROR: you must compile with louvain community libraries for this to work."
318+
<< " Install https://github.com/meelgroup/louvain-community first." << endl;
319+
exit(-1);
320+
#else
321+
double myTime = cpuTime();
322+
verb_print(1, "[arjun] Calculating Louvain Communities...");
325323

326324
vector<vector<Lit>> cnf;
327325
solver->start_getting_small_clauses(
@@ -415,11 +413,8 @@ void Common::calc_community_parts()
415413
}
416414
solver->end_getting_small_clauses();
417415

418-
if (conf.verb) {
419-
cout << "c [mis-comm] Number of communities: " << commpart_incs.size()
420-
<< " T: " << (cpuTime() - myTime)
421-
<< endl;
422-
}
416+
verb_print(1, "[mis-comm] Number of communities: " << commpart_incs.size() \
417+
<< " T: " << (cpuTime() - myTime));
418+
#endif
423419
}
424420

425-
#endif

src/common.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ struct Common
127127
void start_with_clean_sampling_set();
128128
void duplicate_problem();
129129
void get_incidence();
130-
#ifdef LOUVAIN_COMMS
131130
void calc_community_parts();
132-
#endif
133131
void set_up_solver();
134132
vector<Lit> get_cnf();
135133
std::mt19937 random_source = std::mt19937(0);
@@ -266,7 +264,6 @@ struct IncidenceSorterCommPart
266264
if (part_a_inc != part_b_inc) {
267265
return part_a_inc < part_b_inc;
268266
}
269-
return false;
270267

271268
auto a_inc = comm->incidence[a];
272269
auto b_inc = comm->incidence[b];
@@ -311,17 +308,17 @@ struct IncidenceSorterCommPartToOtherComm
311308
template<class T>
312309
void Common::sort_unknown(T& unknown)
313310
{
314-
if (conf.incidence_sort == 1 || conf.incidence_sort >= 10) {
311+
if (conf.unknown_sort == 1 || conf.unknown_sort >= 10) {
315312
std::sort(unknown.begin(), unknown.end(), IncidenceSorter<uint32_t>(incidence));
316-
} else if (conf.incidence_sort == 2) {
313+
} else if (conf.unknown_sort == 2) {
317314
std::sort(unknown.begin(), unknown.end(), IncidenceSorter2<uint32_t>(incidence, incidence_probing));
318-
} else if (conf.incidence_sort == 3) {
315+
} else if (conf.unknown_sort == 3) {
319316
std::sort(unknown.begin(), unknown.end(), IncidenceSorter<uint32_t>(incidence_probing));
320-
} else if (conf.incidence_sort == 4) {
317+
} else if (conf.unknown_sort == 4) {
321318
std::sort(unknown.begin(), unknown.end(), IncidenceSorterCommPart(this));
322-
} else if (conf.incidence_sort == 5) {
319+
} else if (conf.unknown_sort == 5) {
323320
std::sort(unknown.begin(), unknown.end(), IncidenceSorterCommPartToOtherComm(this));
324-
} else if (conf.incidence_sort == 6) {
321+
} else if (conf.unknown_sort == 6) {
325322
std::shuffle(unknown.begin(), unknown.end(), random_source);
326323
} else {
327324
cout << "ERROR: wrong sorting mechanism given" << endl;

src/config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ struct Config {
3838
int distill = 1;
3939
int intree = 1;
4040
int bve_pre_simplify = 1;
41-
int incidence_sort = 10;
41+
int incidence_count = 3; // this determines what incidence MEANS
42+
int unknown_sort = 4; // this determines HOW we sort
4243
int or_gate_based = 1;
4344
int xor_gates_based = 1;
4445
int ite_gate_based = 1;

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void add_arjun_options()
8686
("verb,v", po::value(&conf.verb)->default_value(conf.verb), "verbosity")
8787
("seed,s", po::value(&conf.seed)->default_value(conf.seed), "Seed")
8888
// ("bve", po::value(&conf.bve)->default_value(conf.bve), "bve")
89-
("sort", po::value(&conf.incidence_sort)->default_value(conf.incidence_sort),
89+
("sort", po::value(&conf.unknown_sort)->default_value(conf.unknown_sort),
9090
"Which sorting mechanism.")
9191
("recomp", po::value(&recompute_sampling_set)->default_value(recompute_sampling_set),
9292
"Recompute sampling set even if it's part of the CNF")
@@ -360,7 +360,7 @@ void set_config(ArjunNS::Arjun* arj) {
360360
arj->set_specified_order_fname(conf.specified_order_fname);
361361
arj->set_intree(conf.intree);
362362
arj->set_bve_pre_simplify(conf.bve_pre_simplify);
363-
arj->set_incidence_sort(conf.incidence_sort);
363+
arj->set_unknown_sort(conf.unknown_sort);
364364
if (gates) {
365365
arj->set_or_gate_based(conf.or_gate_based);
366366
arj->set_ite_gate_based(conf.ite_gate_based);

src/simplify.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ bool Common::remove_definable_by_gates()
377377
}
378378
}
379379

380-
381380
if (conf.verb > 4) cout << "c [arjun-simp] XOR Potential: " << potential << endl;
382381

383382
order_sampl_set_for_simp();
@@ -386,7 +385,6 @@ bool Common::remove_definable_by_gates()
386385
// If this is large, it means it'd get removed anyway:
387386
// bottom of the pie, we go through the pile in reverse order to try to remove
388387
vector<double> var_to_rel_position(orig_num_vars, 1.0);
389-
std::sort(sampling_set->begin(), sampling_set->end(), IncidenceSorter<uint32_t>(incidence));
390388
for(uint32_t i = 0; i < sampling_set->size(); i++) {
391389
assert(sampling_set->at(i) < orig_num_vars);
392390
var_to_rel_position[sampling_set->at(i)] = (double)i/(double)sampling_set->size();
@@ -399,7 +397,7 @@ bool Common::remove_definable_by_gates()
399397
continue;
400398
}
401399

402-
// Only try removing if it's at the bottom X percent of incidence_sort
400+
// Only try removing if it's at the bottom X percent of unknown_sort
403401
// If 0.01 is SMALLER, then we have to remove with backward LESS
404402
if (var_to_rel_position[v] < conf.no_gates_below) continue;
405403

@@ -499,7 +497,7 @@ bool Common::remove_definable_by_gates()
499497
void Common::order_sampl_set_for_simp()
500498
{
501499
get_incidence();
502-
std::sort(sampling_set->begin(), sampling_set->end(), IncidenceSorter<uint32_t>(incidence));
500+
sort_unknown(*sampling_set);
503501
std::reverse(sampling_set->begin(), sampling_set->end()); //we want most likely independent as last
504502
}
505503

0 commit comments

Comments
 (0)