Skip to content

Commit e4772c2

Browse files
committed
More efficient memory cleanup
1 parent 9d6ed0d commit e4772c2

File tree

3 files changed

+54
-276
lines changed

3 files changed

+54
-276
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ You can install Radius Clustering using pip:
2626
pip install radius-clustering
2727
```
2828

29-
> Note: This package is not yet available on PyPI. You may need to install it from the source.
29+
> Note: This package is not yet available on PyPI. You may need to install it from the source. See [the documentation](https://lias-laboratory.github.io/radius_clustering/installation.html) for more details.
3030
3131
## Usage
3232

@@ -53,7 +53,11 @@ print(labels)
5353

5454
## Documentation
5555

56-
To build the documentation, you can run the following command, assuming you have Sphinx installed:
56+
You can find the full documentation for Radius Clustering [here](https://lias-laboratory.github.io/radius_clustering/).
57+
58+
### Building the documentation
59+
60+
To build the documentation, you can run the following command, assuming you have all dependencies needed installed:
5761

5862
```bash
5963
cd docs
@@ -73,7 +77,7 @@ If you want to know more about the experiments conducted with the package, pleas
7377

7478
## Contributing
7579

76-
Contributions to MDS Clustering are welcome! Please feel free to submit a Pull Request.
80+
Contributions to Radius Clustering are welcome! Please feel free to submit a Pull Request.
7781

7882
## License
7983

radius_clustering/utils/main-emos.c

Lines changed: 38 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ two vertices adj iif:
179179
*/
180180

181181
static inline int is_2_adj(int marked_node,int test_node){
182-
int adj=0, comneibor=0;
183182
for_each_neighbor(test_node,neibor){
184183
if(neibor==marked_node){
185184
if(!(branched(test_node) && branched(marked_node)))
@@ -522,7 +521,6 @@ static int partition_free_vertices(){
522521
}
523522

524523
static inline void clear_iset(int isetno,int insert_node){
525-
int marked_count=0;
526524
int involved=involved(insert_node);
527525
USED(TMP_STK)=0;
528526
for_each_vec_item(iSET[isetno],int,it){
@@ -558,7 +556,6 @@ static inline void clear_iset(int isetno,int insert_node){
558556
static int improve_partition(int maxlb,int target){
559557
for(int i=SUB_PROBLEM_SIZE-1;i>=CUR_UND_IDX;i--){
560558
int node=CFG[i];
561-
int inserted=0;
562559

563560
set_marked_status(node);
564561
for_each_neighbor(node,neibor){
@@ -622,7 +619,6 @@ static int repartition_vertices(int maxlb){
622619
set_marked_status(neibor);
623620
}
624621

625-
int inserted=0;
626622
for(int j=isno(node)+1;j<MAXIS;j++){
627623
if(USED(iSET[j])==0){
628624
break;
@@ -849,7 +845,7 @@ static int dominated_number(int bnode){
849845
}
850846

851847
int max_dominated_number(){
852-
int max_count=0,max_idx=-1;
848+
int max_count=0;
853849
for(int i=CUR_BRA_IDX,bnode=BNODE(i);bnode!=NONE;bnode=BNODE(++i)){
854850
int count= dominated_number(bnode);
855851
if(count>max_count)
@@ -1370,16 +1366,6 @@ void solve_subproblems(){
13701366
}while(ptr<end);
13711367
}
13721368

1373-
static void print_final_solution(char *inst){
1374-
printf("--------------------------------\n");
1375-
printf("Solution: ");
1376-
for(int i=0;i<USED(VEC_SOLUTION);i++){
1377-
printf("%d ",ITEM(VEC_SOLUTION,i));
1378-
}
1379-
printf("\n");
1380-
printf(">>> %s |V| %d |E| %d FIXED %d INIT %d BEST %d TREE %llu TIME(s) %0.2lf\n",inst,NB_NODE,NB_EDGE,NB_FIXED,INIT_UPPER_BOUND,USED(VEC_SOLUTION),NB_TREE, get_utime());
1381-
}
1382-
13831369
// Define global variables
13841370
extern unsigned long long total_branches = 0;
13851371
extern unsigned long long pruned_branches = 0;
@@ -1501,6 +1487,43 @@ void check_consistance(){
15011487

15021488

15031489
void cleanup(){
1490+
1491+
// Free all allocated memory
1492+
if (CFG != NULL) {
1493+
free(CFG);
1494+
CFG = NULL;
1495+
}
1496+
if (LOC != NULL) {
1497+
free(LOC);
1498+
LOC = NULL;
1499+
}
1500+
if (STATUS != NULL) {
1501+
free(STATUS);
1502+
STATUS = NULL;
1503+
}
1504+
if (PID != NULL) {
1505+
free(PID);
1506+
PID = NULL;
1507+
}
1508+
free_stack(BRA_STK);
1509+
free_stack(FIX_STK);
1510+
free_stack(TMP_STK);
1511+
free_stack(ADJ_STK);
1512+
free_stack(VEC_SOLUTION);
1513+
free_stack(VEC_SUBGRAPHS);
1514+
1515+
for (int i = 0; i <= MAXIS; i++) {
1516+
free_stack(iSET[i]);
1517+
}
1518+
1519+
if (ADJIDX != NULL) {
1520+
free(ADJIDX);
1521+
ADJIDX = NULL;
1522+
}
1523+
1524+
1525+
1526+
free_block();
15041527
// Reset all global variables
15051528
BLOCK_COUNT = 0;
15061529
NB_NODE = 0;
@@ -1529,59 +1552,6 @@ void cleanup(){
15291552
CUT_OFF = 0;
15301553
BEST_SOL_TIME = 0;
15311554
instance[0] = '\0';
1532-
1533-
// Free all allocated memory
1534-
if (CFG != NULL) {
1535-
free(CFG);
1536-
CFG = NULL;
1537-
}
1538-
if (LOC != NULL) {
1539-
free(LOC);
1540-
LOC = NULL;
1541-
}
1542-
if (STATUS != NULL) {
1543-
free(STATUS);
1544-
STATUS = NULL;
1545-
}
1546-
if (PID != NULL) {
1547-
free(PID);
1548-
PID = NULL;
1549-
}
1550-
if (BRA_STK != NULL) {
1551-
free(BRA_STK);
1552-
BRA_STK = NULL;
1553-
}
1554-
if (FIX_STK != NULL) {
1555-
free(FIX_STK);
1556-
FIX_STK = NULL;
1557-
}
1558-
if (TMP_STK != NULL) {
1559-
free(TMP_STK);
1560-
TMP_STK = NULL;
1561-
}
1562-
if (ADJ_STK != NULL) {
1563-
free(ADJ_STK);
1564-
ADJ_STK = NULL;
1565-
}
1566-
if (ADJIDX != NULL) {
1567-
free(ADJIDX);
1568-
ADJIDX = NULL;
1569-
}
1570-
if (VEC_SOLUTION != NULL) {
1571-
free(VEC_SOLUTION);
1572-
VEC_SOLUTION = NULL;
1573-
}
1574-
if (VEC_SUBGRAPHS != NULL) {
1575-
free(VEC_SUBGRAPHS);
1576-
VEC_SUBGRAPHS = NULL;
1577-
}
1578-
1579-
for (int i = 0; i <= MAXIS; i++) {
1580-
if (iSET[i] != NULL) {
1581-
free(iSET[i]);
1582-
iSET[i] = NULL;
1583-
}
1584-
}
15851555
}
15861556

15871557
void handler(int sig) {

0 commit comments

Comments
 (0)