- * Calculate min or max correction factors (as possible) using an LP problem.
- *
- * Args:
- * lp: A linear programming problem with constraints and bounds
- * initialized.
- * direction: The type of factors desired. Use GLP_MAX for max
- * approximation factors (a1, the drift or slope is the
- * largest) and GLP_MIN in the other case.
- *
- * Returns:
- * If the calculation was successful, a new Factors struct. Otherwise, NULL.
- * The calculation will fail if the hull assumptions are not respected.
- */
-static Factors* calculateFactors(glp_prob* const lp, const int direction)
-{
- int retval, status;
- Factors* factors;
-
- glp_set_obj_coef(lp, 1, 0.);
- glp_set_obj_coef(lp, 2, 1.);
-
- glp_set_obj_dir(lp, direction);
- retval= glp_simplex(lp, NULL);
- status= glp_get_status(lp);
-
- if (retval == 0 && status == GLP_OPT)
- {
- factors= malloc(sizeof(Factors));
- factors->offset= glp_get_col_prim(lp, 1);
- factors->drift= glp_get_col_prim(lp, 2);
- }
- else
- {
- factors= NULL;
- }
-
- return factors;
-}
-
-
-/*
- * Calculate min, max and approx correction factors (as possible) using an LP
- * problem.
- *
- * Args:
- * lp: A linear programming problem with constraints and bounds
- * initialized.
- *
- * Returns:
- * Please note that the approximation type may be MIDDLE, INCOMPLETE or
- * ABSENT. Unlike in analysis_chull, ABSENT is also used when the hulls do
- * not respect assumptions.
- */
-static void calculateCompleteFactors(glp_prob* const lp, FactorsCHull* factors)
-{
- factors->min= calculateFactors(lp, GLP_MIN);
- factors->max= calculateFactors(lp, GLP_MAX);
-
- if (factors->min && factors->max)
- {
- factors->type= MIDDLE;
- calculateFactorsMiddle(factors);
- }
- else if (factors->min || factors->max)
- {
- factors->type= INCOMPLETE;
- factors->approx= NULL;
- }
- else
- {
- factors->type= ABSENT;
- factors->approx= NULL;
- }
-}
-
-
-/*
- * Create and initialize an array like AnalysisStatsCHull.allFactors
- *
- * Args:
- * traceNb: number of traces
- *
- * Returns:
- * A new array, which can be freed with freeAllFactors()
- */
-static FactorsCHull** createAllFactors(const unsigned int traceNb)
-{
- FactorsCHull** factorsArray;
- unsigned int i;
-
- factorsArray= malloc(traceNb * sizeof(FactorsCHull*));
- for (i= 0; i < traceNb; i++)
- {
- factorsArray[i]= calloc((i + 1), sizeof(FactorsCHull));
-
- factorsArray[i][i].type= EXACT;
- factorsArray[i][i].approx= malloc(sizeof(Factors));
- factorsArray[i][i].approx->drift= 1.;
- factorsArray[i][i].approx->offset= 0.;
- }
-
- return factorsArray;
-}
-#endif
-
-
-/*
- * Compute synchronization factors using a linear programming approach.
- * Compute the factors using analysis_chull. Compare the two.
- *
- * When the solver library, glpk, is not available at build time, only compute
- * the factors using analysis_chull. This is to make sure that module runs its
- * finalize function so that its graph functions can be called later.
- *
- * Args:
- * syncState: container for synchronization data
- */
-static void finalizeAnalysisEvalLP(SyncState* const syncState)
-{
- AnalysisDataEval* analysisData= syncState->analysisData;
-#ifdef HAVE_LIBGLPK
- unsigned int i, j;
- AnalysisDataCHull* chAnalysisData= analysisData->chullSS->analysisData;
- FactorsCHull** lpFactorsArray;
-
- if (!syncState->stats && !syncState->graphsStream)
- {
- return;
- }
-
- /* Because of matching_distributor, this analysis may be called twice.
- * Only run it once */
- if ((syncState->graphsStream && analysisData->graphs->lps != NULL) ||
- (syncState->stats && analysisData->stats->chFactorsArray != NULL))
- {
- return;
- }
-
- lpFactorsArray= createAllFactors(syncState->traceNb);
-
- if (syncState->stats)
- {
- analysisData->stats->chFactorsArray=
- calculateAllFactors(analysisData->chullSS);
- analysisData->stats->lpFactorsArray= lpFactorsArray;
- }
-
- if (syncState->graphsStream)
- {
- analysisData->graphs->lps= malloc(syncState->traceNb *
- sizeof(glp_prob**));
- for (i= 0; i < syncState->traceNb; i++)
- {
- analysisData->graphs->lps[i]= malloc(i * sizeof(glp_prob*));
- }
- analysisData->graphs->lpFactorsArray= lpFactorsArray;
- }
-
- for (i= 0; i < syncState->traceNb; i++)
- {
- for (j= 0; j < i; j++)
- {
- glp_prob* lp;
-
- // Create the LP problem
- lp= lpCreateProblem(chAnalysisData->hullArray[i][j],
- chAnalysisData->hullArray[j][i]);
-
- // Use the LP problem to find the correction factors for this pair of
- // traces
- calculateCompleteFactors(lp, &lpFactorsArray[i][j]);
-
- if (syncState->graphsStream)
- {
- analysisData->graphs->lps[i][j]= lp;
- }
- else
- {
- glp_delete_prob(lp);
- }
- }
- }
-#endif
-
- g_array_free(analysisData->chullSS->analysisModule->finalizeAnalysis(analysisData->chullSS),
- TRUE);
-}
-
-
-/*
- * Compute synchronization accuracy information using a linear programming
- * approach. Write the neccessary data files and plot lines in the gnuplot
- * script.
- *
- * When the solver library, glpk, is not available at build time nothing is
- * actually produced.