Skip to content

Commit

Permalink
Update comments, help messages, fix formatting. Add license informati…
Browse files Browse the repository at this point in the history
…on to gurobi-plugin file.
  • Loading branch information
aravindacharya committed Mar 28, 2018
1 parent f502d87 commit 5d5b09a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 16 deletions.
8 changes: 4 additions & 4 deletions include/pluto/libpluto.h
Expand Up @@ -148,16 +148,16 @@ struct plutoOptions{
/* Read input from a .scop file */
int readscop;

/* Use PIP as ilp solver. */
/* Use PIP as the ILP solver. */
int pipsolve;

/* Use isl as ilp solver. */
/* Use isl as the ILP solver. */
int islsolve;

/* Use glpk as ilp solver. */
/* Use glpk as the ILP solver. */
int glpk;

/* Use gurobi as ilp solver. */
/* Use gurobi as the ILP solver. */
int gurobi;

/* Use lp instead of ILP. */
Expand Down
2 changes: 1 addition & 1 deletion src/framework-dfp.c
Expand Up @@ -61,7 +61,7 @@ double* pluto_fusion_constraints_feasibility_solve(PlutoConstraints *cst, PlutoM
#ifdef GUROBI
sol = pluto_fcg_constraints_lexmin_gurobi(cst, obj);
#endif
} else {
}else{
#ifdef GLPK
sol = pluto_fcg_constraints_lexmin_glpk(cst, obj);
#endif
Expand Down
52 changes: 47 additions & 5 deletions src/gurobi-plugin.c
@@ -1,10 +1,41 @@
/*
* PLUTO: An automatic parallelizer and locality optimizer
*
* Author: Aravind Acharya
*
* This file is part of Pluto.
*
* Pluto is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* A copy of the GNU General Public Licence can be found in the file
* `LICENSE' in the top-level directory of this distribution.
*
*/

#include <stdio.h>
#ifdef GUROBI
#include "constraints.h"
#include "pluto.h"
#include <math.h>
#include <assert.h>
#include <gurobi_c.h>

/* The file provides an interface to solve Pluto's constraints with Gurobi as
* the (I)LP solver. The file contains routines that creates a (I)LP problem
* from Pluto's constraint matrix. The objective for the optimization problem
* is given as a PlutoMatrix. The constraints are solved a non-null solution
* is returned if a solution exists. The choice of solving ILP/LP can be
* given as a command line option to polycc. */

/* Prints the error message corresponding to the error value passed */
inline void check_error_gurobi(GRBmodel *lp, int error)
{
if(error) {
Expand All @@ -16,6 +47,9 @@ inline void check_error_gurobi(GRBmodel *lp, int error)
}
}

/* Creates a double array for gurobi objective from the objective matrix.
* The input PlutoMatrix should have a single row and the column elements
* correspond to the coefficients of the variables in the objective function. */
double* get_gurobi_objective_from_pluto_matrix(PlutoMatrix *obj)
{
int j;
Expand Down Expand Up @@ -69,7 +103,7 @@ void set_gurobi_constraints_from_pluto_constraints (GRBmodel *lp, const PlutoCon
free(value);
}

/* Retrives ilp solution from the input glpk problem.
/* Retrives ilp solution from the input gurobi problem.
* Assumes that the optimal solution exists and has been found*/
int64* get_ilp_solution_from_gurobi_problem(GRBmodel *lp)
{
Expand All @@ -91,6 +125,8 @@ int64* get_ilp_solution_from_gurobi_problem(GRBmodel *lp)
return sol;
}

/* Retrives lp solution from the input gurobi problem.
* Assumes that the optimal solution exists and has been found*/
double* get_lp_solution_from_gurobi_problem(GRBmodel *lp)
{
int num_cols, error, i;
Expand Down Expand Up @@ -118,10 +154,12 @@ inline void find_optimal_solution_gurobi(GRBmodel *lp, double tol)
GRBsetdblparam(GRBgetenv(lp), "IntFeasTol", tol);

GRBoptimize(lp);

}


/* Solve the gurobi problem lp. If optimal solution is found, then it returns 0.
* The caller can retrive the funtion from the gurobi model object lp. If the
* problem is infeasible then the routine returns 1. If the problem is
* unbounded, program terminates with the corresponding error message. */
int pluto_constraints_solve_gurobi(GRBmodel *lp, double tol)
{
int optim_status;
Expand Down Expand Up @@ -258,6 +296,10 @@ GRBmodel *get_scaling_lp_gurobi(double *fpsol, int num_sols, double **val, int *
return lp;
}

/* The rational solutions of pluto-lp are scaled on a per connected component basis.
* The following routine returns the maximum scaling factor among the scaling
* factors of each connected component; the largest among the first num_ccs
* elements of the array sol*/
int64 get_max_scale_factor(double *sol, int num_ccs)
{
int i, max;
Expand Down Expand Up @@ -374,7 +416,8 @@ int64 *pluto_prog_constraints_lexmin_gurobi(const PlutoConstraints *cst,

}


/* The routine is called during the construction of FCG in pluto-lp-dfp.
* It returns a rational solution if the optimal solution exists else it returns NULL. */
double *pluto_fcg_constraints_lexmin_gurobi(const PlutoConstraints* cst, PlutoMatrix* obj)
{
double *grb_obj, *sol;
Expand Down Expand Up @@ -419,6 +462,5 @@ double *pluto_fcg_constraints_lexmin_gurobi(const PlutoConstraints* cst, PlutoMa
sol = get_lp_solution_from_gurobi_problem(lp);
return sol;
}

}
#endif
8 changes: 4 additions & 4 deletions src/main.c
Expand Up @@ -62,7 +62,7 @@ void usage_message(void)
fprintf(stdout, " --islsolve [default] Use ISL as ILP solver (default)\n");
fprintf(stdout, " --pipsolve Use PIP as ILP solver\n");
#ifdef GLPK
fprintf(stdout, " --glpk Use GLPK as ILP solver\n");
fprintf(stdout, " --glpk Use GLPK as ILP solver (default in case of pluto-lp and pluto-dfp)\n");
#endif
#if defined GLPK || defined GUROBI
fprintf(stdout, " --lp Solve MIP instead of ILP\n");
Expand Down Expand Up @@ -366,10 +366,10 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
options->parallel = 1;
}

#ifdef GLPK
if (options->gurobi) {
options->islsolve = 0;
}
#ifdef GLPK
if (options->lp && !(options->glpk || options->gurobi)) {
printf("[pluto]: LP option available with a LP solver only. Using GLPK for lp solving\n");
options->glpk = 1;
Expand All @@ -392,8 +392,8 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"

#endif

if(options->dfp && !(options->glpk || options->gurobi)) {
printf ("[pluto]: ERROR: DFP framework currently supported with GLPK solver only. Configure Pluto with --enable-glpk \n");
if (options->dfp && !(options->glpk || options->gurobi)) {
printf ("[pluto]: ERROR: DFP framework is currently supported with GLPK or GUROBI solvers only. Run ./configure --help to for more information on using different solvers with Pluto.\n");
pluto_options_free(options);
usage_message();
return 1;
Expand Down
3 changes: 1 addition & 2 deletions src/pluto.c
Expand Up @@ -385,8 +385,7 @@ int64 *pluto_prog_constraints_lexmin(PlutoConstraints *cst, PlutoProg *prog)
free(val);
free(index);
}
}
else {
}else{
t_start = rtclock();
sol = pluto_constraints_lexmin_pip(newcst, DO_NOT_ALLOW_NEGATIVE_COEFF);
prog->mipTime += rtclock()-t_start;
Expand Down

0 comments on commit 5d5b09a

Please sign in to comment.