| 1 |
/* |
| 2 |
* This file is part of MPSolve 3.2.2 |
| 3 |
* |
| 4 |
* Copyright (C) 2001-2020, Dipartimento di Matematica "L. Tonelli", Pisa. |
| 5 |
* License: http://www.gnu.org/licenses/gpl.html GPL version 3 or higher |
| 6 |
* |
| 7 |
* Authors: |
| 8 |
* Leonardo Robol <[email protected]> |
| 9 |
*/ |
| 10 |
|
| 11 |
/** |
| 12 |
* @file |
| 13 |
* |
| 14 |
* @brief Data structures for cluster analysis and some accessors and |
| 15 |
* internal functions. |
| 16 |
*/ |
| 17 |
|
| 18 |
#ifndef MPS_CLUSTER_H_ |
| 19 |
#define MPS_CLUSTER_H_ |
| 20 |
|
| 21 |
#define MPS_ALL_CLUSTERS -1 |
| 22 |
|
| 23 |
#include <mps/mps.h> |
| 24 |
|
| 25 |
MPS_BEGIN_DECLS |
| 26 |
|
| 27 |
/** |
| 28 |
* @brief This struct represent a root inside of a <code>mps_cluster</code>. |
| 29 |
*/ |
| 30 |
struct mps_root { |
| 31 |
/** |
| 32 |
* @brief Index of the root that is considered. |
| 33 |
*/ |
| 34 |
long int k; |
| 35 |
|
| 36 |
/** |
| 37 |
* @brief Next root, or <code>NULL</code> if this is the last root of the cluster. |
| 38 |
*/ |
| 39 |
mps_root * next; |
| 40 |
|
| 41 |
/** |
| 42 |
* @brief Pointer to the previous root, or <code>NULL</code> if there is no previous |
| 43 |
* root. |
| 44 |
*/ |
| 45 |
mps_root * prev; |
| 46 |
}; |
| 47 |
|
| 48 |
/** |
| 49 |
* @brief A cluster of <code>mps_roots</code>. |
| 50 |
*/ |
| 51 |
struct mps_cluster { |
| 52 |
/** |
| 53 |
* @brief Number of roots in the cluster. |
| 54 |
*/ |
| 55 |
long int n; |
| 56 |
|
| 57 |
/** |
| 58 |
* @brief Pointer to the first root in the cluster. |
| 59 |
*/ |
| 60 |
mps_root * first; |
| 61 |
|
| 62 |
/** |
| 63 |
* @brief Internal mutex used to perform operations in a thread-safe |
| 64 |
* way. |
| 65 |
*/ |
| 66 |
pthread_mutex_t lock; |
| 67 |
}; |
| 68 |
|
| 69 |
/** |
| 70 |
* @brief Cluster held in a mps_clusterization. |
| 71 |
*/ |
| 72 |
struct mps_cluster_item { |
| 73 |
/** |
| 74 |
* @brief Pointer to the actual cluster. |
| 75 |
*/ |
| 76 |
mps_cluster * cluster; |
| 77 |
|
| 78 |
/** |
| 79 |
* @brief Next cluster in the clusterization, or NULL if there is no such |
| 80 |
* cluster. |
| 81 |
*/ |
| 82 |
mps_cluster_item * next; |
| 83 |
|
| 84 |
/** |
| 85 |
* @brief Previous cluster in the clusterizaion or NULL if there is no |
| 86 |
* such cluster. |
| 87 |
*/ |
| 88 |
mps_cluster_item * prev; |
| 89 |
|
| 90 |
/** |
| 91 |
* @brief This pointer to the cluster from which the cluster were |
| 92 |
* detached, if any. Otherwise it is set to NULL. |
| 93 |
*/ |
| 94 |
mps_cluster_item * detached; |
| 95 |
}; |
| 96 |
|
| 97 |
/** |
| 98 |
* @brief A list of <code>mps_cluster</code>. |
| 99 |
*/ |
| 100 |
struct mps_clusterization { |
| 101 |
/** |
| 102 |
* @brief Number of cluster in the clusterization. |
| 103 |
*/ |
| 104 |
long int n; |
| 105 |
|
| 106 |
/** |
| 107 |
* @brief Pointer to the first cluster in the clusterization. |
| 108 |
*/ |
| 109 |
mps_cluster_item * first; |
| 110 |
}; |
| 111 |
|
| 112 |
/********************************************************************************* |
| 113 |
* FUNCTIONS * |
| 114 |
*********************************************************************************/ |
| 115 |
|
| 116 |
void mps_cluster_reset (mps_context * s); |
| 117 |
void mps_fcluster (mps_context * s, double * frad, int nf); |
| 118 |
void mps_dcluster (mps_context * s, rdpe_t * drad, int nf); |
| 119 |
void mps_mcluster (mps_context * s, rdpe_t * drad, int nf); |
| 120 |
void mps_debug_cluster_structure (mps_context * s); |
| 121 |
void mps_cluster_analysis (mps_context * ctx, mps_polynomial * p); |
| 122 |
|
| 123 |
/* Functions for mps_cluster */ |
| 124 |
mps_cluster * mps_cluster_empty (mps_context * s); |
| 125 |
mps_cluster * mps_cluster_with_root (mps_context * s, long int root_index); |
| 126 |
void mps_cluster_free (mps_context * s, mps_cluster * cluster); |
| 127 |
mps_root * mps_cluster_insert_root (mps_context * s, mps_cluster * cluster, long int root_index); |
| 128 |
void mps_cluster_remove_root (mps_context * s, mps_cluster * cluster, mps_root * root); |
| 129 |
mps_cluster * mps_cluster_join (mps_context * s, mps_cluster * cluster_a, mps_cluster * cluster_b); |
| 130 |
|
| 131 |
/* Functions for mps_clusterization */ |
| 132 |
mps_clusterization * mps_clusterization_empty (mps_context * s); |
| 133 |
mps_cluster_item * mps_clusterization_insert_cluster (mps_context * s, mps_clusterization * c, mps_cluster * cluster); |
| 134 |
void mps_clusterization_pop_cluster (mps_context * s, mps_clusterization * c, mps_cluster_item * cluster_item); |
| 135 |
void mps_clusterization_remove_cluster (mps_context * s, mps_clusterization * c, mps_cluster_item * cluster_item); |
| 136 |
void mps_clusterization_free (mps_context * s, mps_clusterization * c); |
| 137 |
void mps_clusterization_detach_clusters (mps_context * s, mps_clusterization * c); |
| 138 |
void mps_clusterization_reassemble_clusters (mps_context * s, mps_clusterization * c); |
| 139 |
|
| 140 |
void mps_cluster_detach (mps_context * s, mps_cluster * cluster); |
| 141 |
|
| 142 |
MPS_END_DECLS |
| 143 |
|
| 144 |
#endif /* endif MPS_CLUSTER_H_ */ |