import it.ssc.log.SscLogger;
import it.ssc.pl.milp.LP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputString;
public class Esempio {
public static void main(String[] args) throws Exception {
String lp_string =
" 1 3 max . \n" +
" 1 1 ge -1 \n" +
" 1 1.4 le 6 \n" +
"-5 3 eq 5";
InputString lp_input = new InputString(lp_string);
lp_input.setInputFormat("X1:double, X2:double, TYPE:varstring(3), RHS:double");
LP lp = new LP(lp_input);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
else SscLogger.log("Soluzione non ottima:"+solution_type);
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.ConsType;
import it.ssc.pl.milp.Constraint;
import it.ssc.pl.milp.GoalType;
import it.ssc.pl.milp.LP;
import it.ssc.pl.milp.LinearObjectiveFunction;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.pl.milp.ListConstraints;
import java.util.ArrayList;
public class Esempio {
public static void main(String[] args) throws Exception {
double A[][]={
{ 1.0 , 1.0 },
{ 1.0 , 1.4 },
{-5.0 , 3.0 } } ;
double b[]= {-1.0, 6.0 ,5.0 };
double c[]= { 1.0, 3.0 };
ConsType[] rel= {ConsType.GE, ConsType.LE, ConsType.EQ};
LinearObjectiveFunction fo = new LinearObjectiveFunction(c, GoalType.MAX);
ListConstraints constraints = new ListConstraints();
for(int i=0; i < A.length; i++) {
constraints.add(new Constraint(A[i], rel[i], b[i]));
}
LP lp = new LP(fo,constraints);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.LP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputString;
public class Esempio {
public static void main(String[] args) throws Exception {
String lp_string =
" 1 3 max . \n" +
" 1 1 ge 1 \n" +
" 1 1.4 le 6 \n" +
"-5 3 eq 5 \n" +
" 1 . upper . \n" +
"-1 . lower . \n" ;
InputString lp_input = new InputString(lp_string);
lp_input.setInputFormat("X1-X2:double, TYPE:varstring(8), RHS:double");
LP lp = new LP(lp_input);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Variabile "+var.getName() +": "+var.getLower() + " <= ["+var.getValue()+"] <= "+var.getUpper());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.ConsType;
import it.ssc.pl.milp.Constraint;
import it.ssc.pl.milp.GoalType;
import it.ssc.pl.milp.LP;
import it.ssc.pl.milp.LinearObjectiveFunction;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import static it.ssc.pl.milp.LP.NaN;
import java.util.ArrayList;
public class Esempio {
public static void main(String[] args) throws Exception {
double A[][]={
{ 1.0 , 1.0 },
{ 1.0 , 1.4 },
{-5.0 , 3.0 },
{ 1.0 , NaN },
{-1.0 , NaN }} ;
double b[]= { 1.0, 6.0 ,5.0, NaN, NaN };
double c[]= { 1.0, 3.0 };
ConsType[] rel= {ConsType.GE, ConsType.LE, ConsType.EQ, ConsType.UPPER, ConsType.LOWER};
LinearObjectiveFunction f = new LinearObjectiveFunction(c, GoalType.MAX);
ArrayList< Constraint > constraints = new ArrayList< Constraint >();
for(int i=0; i < A.length; i++) {
constraints.add(new Constraint(A[i], rel[i], b[i]));
}
LP lp = new LP(f,constraints);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import java.util.ArrayList;
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.GoalType;
import it.ssc.pl.milp.LP;
import it.ssc.pl.milp.LinearObjectiveFunction;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
public class Esempio {
public static void main(String[] args) throws Exception {
ArrayList< String > constraints = new ArrayList< String >();
constraints.add("min: 3Y +2x2 +4x3 +7x4 +8X5 ");
constraints.add("5Y +2x2 +3X4 >= 9");
constraints.add("3Y + X2 +X3 +5X5 >= 12");
constraints.add("6Y+3.0x2 +4X3 +5X4 <= 124");
constraints.add(" y + 3x2 +3X4 +6X5 <= 854");
LP lp = new LP(constraints);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution soluzione=lp.getSolution();
for(Variable var:soluzione.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore :"+var.getValue());
}
SscLogger.log("Valore ottimo:"+soluzione.getOptimumValue());
}
}
}
import java.util.ArrayList;
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.*;
public class Esempio {
public static void main(String[] args) throws Exception {
ArrayList< String > constraints = new ArrayList< String >();
constraints.add("min: 3Y +2x2 +4Z +7x4 +8X5 ");
constraints.add(" 5Y +2x2 +3X4 >= 9");
constraints.add(" 3Y + X2 + Z +5X5 >= 12");
constraints.add(" 6Y +3.0x2 +4Z +5X4 <= 124");
constraints.add(" Y +3x2 +3X4 +6X5 <= 854");
constraints.add("-1<= x2 <= 6");
constraints.add("1 <= z <= .");
LP lp = new LP(constraints);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution soluzione=lp.getSolution();
for(Variable var:soluzione.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore :"+var.getValue());
}
SscLogger.log("Valore ottimo:"+soluzione.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.FormatTypeInput.FormatType;
import it.ssc.pl.milp.LP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputString;
public class Esempio {
public static void main(String[] args) throws Exception {
String lp_sparse =
// TYPE COL_ ROW_ COEF
" MAX . costo . \n" +
" GE . row1 . \n" +
" LE . row2 . \n" +
" EQ . row3 . \n" +
" UPPER . lim_sup . \n" +
" LOWER . lim_inf . \n" +
" . X1 costo 1 \n" +
" . X1 row1 1 \n" +
" . X1 row2 1 \n" +
" . X1 row3 -5 \n" +
" . X1 lim_sup 1 \n" +
" . X1 lim_inf -1 \n" +
" . X2 costo 3 \n" +
" . X2 row1 1 \n" +
" . X2 row2 1.4 \n" +
" . X2 row3 3 \n" +
" . X2 lim_sup . \n" +
" . X2 lim_inf . \n" +
" . RHS row1 1 \n" +
" . RHS row2 6 \n" +
" . RHS row3 5 \n" ;
InputString lp_input = new InputString(lp_sparse);
lp_input.setInputFormat("TYPE:varstring(5), COL_:varstring(3) , ROW_:varstring(7), COEF:double");
LP lp = new LP(lp_input,FormatType.SPARSE);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.LP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputFile;
public class Example {
public static void main(String[] args) throws Exception {
InputFile input = new InputFile("c:/dati_pl/pl_problem.txt");
input.setInputFormat("Y1-Y5:double, TYPE:varstring(10), RHS:double");
LP lp=new LP(input);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution soluzione=lp.getSolution();
for(Variable var:soluzione.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore :"+var.getValue());
}
SscLogger.log("Valore ottimo:"+soluzione.getOptimumValue());
}
}
}
import it.ssc.context.Context;
import it.ssc.context.Session;
import it.ssc.library.Library;
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.FormatTypeInput.FormatType;
import it.ssc.pl.milp.LP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.Input;
import java.sql.Connection;
import oracle.jdbc.pool.OracleDataSource;
public class Esempio {
public static void main(String[] args) throws Exception {
Session session = null;
try {
session = Context.createNewSession();
Library lib_ora=session.addLibrary("DB_ORACLE", connOracle());
Input pl_oracle=lib_ora.getInput("TAB_PL_PROBLEM");
LP lp = new LP(pl_oracle,session,FormatType.SPARSE);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
finally {
session.close();
}
}
private static Connection connOracle() throws Exception {
OracleDataSource ods = new OracleDataSource();
String URL = "jdbc:oracle:thin:@//192.168.243.134:1521/XE";
ods.setURL(URL);
ods.setUser("user_pl");
ods.setPassword("ora655");
return ods.getConnection();
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.LP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputString;
public class Esempio {
public static void main(String[] args) throws Exception {
String lp_string =
"5 4 1 3 max . \n" +
"4 3 1 1 ge 2 \n" +
"1 -2 1 -1 le 2 \n" +
"3 2 1 1.4 le 6 \n" +
"9 8 4 1.7 le 7 \n" +
"5 3 -1 2.4 le 9 \n" +
"3 -2 -5 3 le 5 ";
InputString lp_input = new InputString(lp_string);
lp_input.setInputFormat("V1-V4:double, TYPE:varstring(8), RHS:double");
LP lp = new LP(lp_input);
SscLogger.log("Numero di iterazioni di default:"+lp.getNumMaxIteration());
lp.setNumMaxIteration(5);
lp.setJustTakeFeasibleSolution(true); //imposto la ricerca di una soluzione ammissibile ,
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.FEASIBLE) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore assunto dalla soluzione ammissibile sulla f.o.:"+solution.getOptimumValue());
}
else if(solution_type==SolutionType.VUOTUM) {
SscLogger.log("La fase 1 del simplesso non ha trovato soluzioni ammissibili:("+solution_type+")");
}
else if(solution_type==SolutionType.ILLIMITATUM) {
SscLogger.log("Ottimo illimitato:("+solution_type+")");
}
else if(solution_type==SolutionType.MAX_ITERATIUM) {
SscLogger.log("Raggiunto il numero massimo di iterazioni:("+solution_type+")");
}
else if(solution_type==SolutionType.OPTIMUM) {
//questa sezione non verrà mai raggiunta in quanto avendo impostato
//setJustTakeFeasibleSolution(true), il simplesso può solo restituire soluzioni ammissibili
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.*;
import java.util.ArrayList;
import java.util.Random;
public class Esempio {
public static void main(String[] args) throws Exception {
LP lp = new LP("C:\\ssc_project\\ssc\\dati_testo\\pl_proble.txt");
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution soluzione=lp.getSolution();
for(Variable var:soluzione.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore :"+var.getValue());
}
for(SolutionConstraint sol_constraint: soluzione.getSolutionConstraint()) {
SscLogger.log("Vincolo "+sol_constraint.getName()+" : valore="+sol_constraint.getValue() +
"[ "+sol_constraint.getRel()+" "+sol_constraint.getRhs()+" ]" );
}
SscLogger.log("Valore ottimo:"+soluzione.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.FormatTypeInput.FormatType;
import it.ssc.pl.milp.LP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputFile;
public class Esempio {
public static void main(String[] args) throws Exception {
InputFile input_sparse = new InputFile("C:/ssc_project/sparse_problem.txt");
input_sparse.setInputFormat("TYPE:varstring(5), COL_:varstring(3) , ROW_:varstring(7), COEF:double");
LP lp = new LP(input_sparse,FormatType.SPARSE);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.*;
import java.util.ArrayList;
import java.util.Random;
public class Esempio {
public static void main(String arg[]) throws Exception {
final int M = 445; // rows
final int N = 345; // cols
Random random = new Random();
double[] c = new double[N];
double[] b = new double[M];
double[][] A = new double[M][N];
for (int j = 0; j < N; j++) c[j] = (double) (random.nextInt(20));
for (int i = 0; i < M; i++) b[i] = (double) random.nextInt(100000000);
for (int i = 0; i < M; i++)
for (int j = 0; j < N; j++) A[i][j] = (double) random.nextInt(10);
LinearObjectiveFunction f = new LinearObjectiveFunction(c, GoalType.MAX);
ArrayList< Constraint > constraints = new ArrayList< Constraint >();
for(int i=0; i < A.length; i++) {
constraints.add(new Constraint(A[i], ConsType.LE, b[i]));
}
LP lp = new LP(f,constraints);
lp.setCEpsilon(EPSILON._1E_M5);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " value:"+var.getValue());
}
SscLogger.log("Valore f.o. :"+solution.getOptimumValue());
}
else SscLogger.log("Soluzione non ottima. Tipo di soluzione:"+solution_type);
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.LP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputString;
import it.ssc.pl.milp.util.LPThreadsNumber;
public class Esempio {
public static void main(String[] args) throws Exception {
String lp_string =
" 1 3 max . \n" +
" 1 1 ge -1 \n" +
" 1 1.4 le 6 \n" +
"-5 3 eq 5";
InputString lp_input = new InputString(lp_string);
lp_input.setInputFormat("X1:double, X2:double, TYPE:varstring(3), RHS:double");
LP lp = new LP(lp_input);
lp.setThreadsNumber(LPThreadsNumber.N_4);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
else SscLogger.log("Soluzione non ottima:"+solution_type);
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.MILP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputString;
public class Esempio {
public static void main(String[] args) throws Exception {
String milp_string=
"3 1 4 7 8 min . " +"\n"+
"5 2 0 3 0 le 9 " +"\n"+
"3 1 1 0 5 ge 12" +"\n"+
"6 3 4 5 0 ge 124" +"\n"+
"1 3 0 3 6 ge 854" +"\n"+
"0 1 1 0 0 lower . " +"\n"+
". 6 . . . upper . " +"\n"+
"0 1 1 1 1 integer . " +"\n" ;
InputString milp_input = new InputString(milp_string);
milp_input.setInputFormat("X1-X5:double, TYPE:varstring(20), RHS:double");
MILP milp=new MILP(milp_input);
SolutionType solution_type= milp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=milp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.ConsType;
import it.ssc.pl.milp.Constraint;
import it.ssc.pl.milp.GoalType;
import it.ssc.pl.milp.LinearObjectiveFunction;
import it.ssc.pl.milp.MILP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import static it.ssc.pl.milp.LP.NaN;
import java.util.ArrayList;
public class Esempio {
public static void main(String[] args) throws Exception {
double A[][]={
{ 1.0 , 1.0 },
{ 1.0 , 1.4 },
{-5.0 , 3.0 },
{ 1.0 , 1.0 }, //rigo della matrice per la definizione degli integer
} ;
double b[]= { 1.0, 6.0 ,5.0, NaN};
double c[]= { 1.0, 3.0 };
ConsType[] rel= {ConsType.GE, ConsType.LE, ConsType.LE, ConsType.INT};
LinearObjectiveFunction f = new LinearObjectiveFunction(c, GoalType.MAX);
ArrayList< Constraint > constraints = new ArrayList< Constraint >();
for(int i=0; i < A.length; i++) {
constraints.add(new Constraint(A[i], rel[i], b[i]));
}
MILP lp = new MILP(f,constraints);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.FormatTypeInput.FormatType;
import it.ssc.pl.milp.MILP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputString;
public class Esempio {
public static void main(String[] args) throws Exception {
String lp_sparse =
// TYPE COL_ ROW_ COEF
" MAX . costo . \n" +
" GE . row1 . \n" +
" LE . row2 . \n" +
" EQ . row3 . \n" +
" UPPER . lim_sup . \n" +
" LOWER . lim_inf . \n" +
" INTEGER . var_int . \n" +
" . Y1 costo 1 \n" +
" . Y1 row1 1 \n" +
" . Y1 row2 1 \n" +
" . Y1 row3 -5 \n" +
" . Y1 lim_sup 1 \n" +
" . Y1 lim_inf -1 \n" +
" . Y2 costo 3 \n" +
" . Y2 row1 1 \n" +
" . Y2 row2 1.4 \n" +
" . Y2 row3 3 \n" +
" . Y2 lim_sup . \n" +
" . Y2 lim_inf . \n" +
" . Y2 var_int 1 \n" +
" . RHS row1 1 \n" +
" . RHS row2 6 \n" +
" . RHS row3 5 \n" ;
InputString lp_input = new InputString(lp_sparse);
lp_input.setInputFormat("TYPE:varstring(7), COL_:varstring(3) , ROW_:varstring(7), COEF:double");
MILP lp = new MILP(lp_input,FormatType.SPARSE);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.MILP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputString;
public class Esempio {
public static void main(String[] args) throws Exception {
String milp_string=
"3 1 4 7 8 min . " +"\n"+
"5 2 0 3 0 le 9 " +"\n"+
"3 1 1 0 5 ge 12" +"\n"+
"6 3 4 5 0 ge 124" +"\n"+
"1 3 0 3 6 ge 854" +"\n"+
"0 1 1 0 0 lower . " +"\n"+
". 6 . . . upper . " +"\n"+
"0 1 0 0 1 integer . " +"\n"+
"1 0 0 1 0 binary . " +"\n";
InputString milp_input = new InputString(milp_string);
milp_input.setInputFormat("K1-K5:double, TYPE:varstring(20), RHS:double");
MILP milp=new MILP(milp_input);
SolutionType solution_type= milp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=milp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import static it.ssc.pl.milp.LP.NaN;
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.*;
import java.util.ArrayList;
public class Esempio {
public static void main(String[] args) throws Exception {
double A[][]={
{ 1.0 , 1.0 },
{ 1.0 , 1.4 },
{-5.0 , 3.0 },
{ 1.0 , 0.0 }, //definizione degli integer
{ 0.0 , 1.0 }, //definizione dei binary
} ;
double b[]= { 1.0, 6.0 ,5.0, NaN, NaN};
double c[]= { 1.0, 3.0 };
ConsType[] rel= {ConsType.GE, ConsType.LE, ConsType.LE, ConsType.INT , ConsType.BIN};
LinearObjectiveFunction f = new LinearObjectiveFunction(c, GoalType.MAX);
ArrayList< Constraint > constraints = new ArrayList< Constraint >();
for(int i=0; i < A.length; i++) {
constraints.add(new Constraint(A[i], rel[i], b[i]));
}
MILP lp = new MILP(f,constraints);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.FormatTypeInput.FormatType;
import it.ssc.pl.milp.MILP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputString;
public class Esempio {
public static void main(String[] args) throws Exception {
String lp_sparse =
// TYPE COL_ ROW_ COEF
" MAX . costo . \n" +
" GE . row1 . \n" +
" LE . row2 . \n" +
" LE . row3 . \n" +
" UPPER . lim_sup . \n" +
" LOWER . lim_inf . \n" +
" INTEGER . var_int . \n" +
" BINARY . var_bin . \n" +
" . Y1 costo 1 \n" +
" . Y1 row1 1 \n" +
" . Y1 row2 1 \n" +
" . Y1 row3 -5 \n" +
" . Y1 lim_sup 1 \n" +
" . Y1 lim_inf -1 \n" +
" . Y1 var_bin 1 \n" +
" . Y2 costo 3 \n" +
" . Y2 row1 1 \n" +
" . Y2 row2 1.4 \n" +
" . Y2 row3 3 \n" +
" . Y2 lim_sup . \n" +
" . Y2 lim_inf . \n" +
" . Y2 var_int 1 \n" +
" . RHS row1 1 \n" +
" . RHS row2 6 \n" +
" . RHS row3 5 \n" ;
InputString lp_input = new InputString(lp_sparse);
lp_input.setInputFormat("TYPE:varstring(7), COL_:varstring(3) , ROW_:varstring(7), COEF:double");
MILP milp = new MILP(lp_input,FormatType.SPARSE);
SolutionType solution_type=milp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=milp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import java.util.ArrayList;
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.*;
public class Esempio {
public static void main(String[] args) throws Exception {
ArrayList< String > constraints = new ArrayList< String >();
constraints.add("min: 3x1 +X2 +4x3 +7x4 +8X5 ");
constraints.add("5x1 +2x2 +3X4 >= 9");
constraints.add("3x1 + X2 +X3 +5X5 >= 12.5");
constraints.add("6X1+3.0x2 +4X3 +5X4 <= 124");
constraints.add(" X1 + 3x2 +3X4 +6X5 <= 854");
constraints.add(" int x2, X3 ");
MILP milp = new MILP(constraints);
SolutionType solution_type=milp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution soluzione=milp.getSolution();
for(Variable var:soluzione.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore :"+var.getValue());
}
SscLogger.log("Valore ottimo:"+soluzione.getOptimumValue());
}
}
}
import it.ssc.context.exception.InvalidSessionException;
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.*;
import java.util.ArrayList;
import static it.ssc.pl.milp.LP.NaN;
public class Esempio {
public static void main(String arg[]) throws InvalidSessionException, Exception {
double[] c = { 2, 2, 2, 2, 2 ,2, 2, 2, 2, 2,2 ,2 ,2 };
double[] b = {1000, 1234, 1000, 1000, 1000, 1000, 1000, 1000, 1000};
double[][] A ={ { 2., 9. ,7. ,5. ,9. ,6. ,3., 7., 8. ,7. ,5. ,3. ,1. },
{ 4. ,1. ,2. ,3. ,6. ,4. ,5. ,2. ,8. ,5. ,3. ,4., 7. },
{ 3. ,4. ,2. ,5. ,7. ,6. ,3. ,5. ,7. ,4. ,6. ,8. ,6. },
{ 4. ,6. ,9. ,8. ,7. ,6. ,5. ,4. ,3. ,2. ,3. ,5. ,6. },
{ 4. ,4. ,7. ,5. ,3. ,8. ,5. ,6. ,3. ,5. ,6. ,4. ,6. },
{ 2. ,6. ,4. ,5. ,7. ,5. ,6. ,4. ,6. ,7. ,4. ,4. ,6. },
{ 4. ,6. ,9. ,8. ,3. ,6. ,5. ,5. ,3. ,2. ,9. ,5. ,6. },
{ 4. ,5. ,7. ,8. ,3. ,8. ,3. ,6. ,3. ,5. ,6. ,1. ,6. },
{ 2., 2., 4., 3., 7. ,5. ,9. ,4. ,6. ,7. ,8. ,4., 6. }};
double[] upper ={ 190.5, NaN, NaN, NaN, NaN ,NaN ,NaN ,NaN ,35.0 ,NaN ,NaN ,NaN, NaN };
double[] integer ={ 1.0, 1.0, 1.0, 1.0, 1.0 ,1.0 ,1.0 ,1.0 ,1.0 ,1.0 ,1.0 ,1.0, 1.0 };
LinearObjectiveFunction f = new LinearObjectiveFunction(c, GoalType.MAX);
ArrayList< Constraint > constraints = new ArrayList< Constraint >();
for(int i=0; i< A.length; i++) {
constraints.add(new Constraint(A[i], ConsType.LE, b[i]));
}
constraints.add(new Constraint(upper, ConsType.UPPER, NaN));
constraints.add(new Constraint(integer, ConsType.INT , NaN));
MILP milp = new MILP(f,constraints);
SolutionType solution=milp.resolve();
if(solution==SolutionType.OPTIMUM) {
Solution sol=milp.getSolution();
Solution sol_relax=milp.getRelaxedSolution();
Variable[] var_int=sol.getVariables();
Variable[] var_relax=sol_relax.getVariables();
for(int _i=0; _i< var_int.length;_i++) {
SscLogger.log("Nome variabile :"+var_int[_i].getName() + " valore:"+var_int[_i].getValue()+
" ["+var_relax[_i].getValue()+"]");
}
SscLogger.log("valore ottimo:"+sol.getOptimumValue() +" ["+sol_relax.getOptimumValue()+"]");
}
}
}
import java.util.ArrayList;
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.*;
public class Esempio {
public static void main(String[] args) throws Exception {
ArrayList< String > constraints = new ArrayList< String >();
constraints.add("min: 3x1 +X2 +4x3 +7x4 +8X5 ");
constraints.add("5x1 +2x2 +3X4 >= 9");
constraints.add("3x1 + X2 +X3 +5X5 >= 12.5");
constraints.add("6X1+3.0x2 +4X3 +5X4 <= 124");
constraints.add(" X1 + 3x2 +3X4 +6X5 <= 854");
constraints.add(" int x2, X3 ");
MILP milp = new MILP(constraints);
SolutionType solution_type=milp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution soluzione=milp.getSolution();
for(Variable var:soluzione.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore :"+var.getValue());
}
for(SolutionConstraint sol_constraint: soluzione.getSolutionConstraint()) {
SscLogger.log("Vincolo "+sol_constraint.getName()+" : valore="+sol_constraint.getValue() +
"[ "+sol_constraint.getRel()+" "+sol_constraint.getRhs()+" ]" );
}
SscLogger.log("Valore ottimo:"+soluzione.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.MILP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputString;
public class Esempio {
public static void main(String[] args) throws Exception {
String milp_string=
"3 1 4 7 8 min . " +"\n"+
"5 2 0 3 0 le 9 " +"\n"+
"3 1 1 0 5 ge 12" +"\n"+
"6 3 4 5 0 ge 124" +"\n"+
"1 3 0 3 6 ge 854" +"\n"+
"0 1 1 0 0 lower . " +"\n"+
". 6 . . . upper . " +"\n"+
"0 1 0 0 1 integer . " +"\n"+
"1 0 0 1 0 binary . " +"\n"+
"0 1 0 0 0 semicont . " +"\n";
InputString milp_input = new InputString(milp_string);
milp_input.setInputFormat("K1-K5:double, TYPE:varstring(20), RHS:double");
MILP milp=new MILP(milp_input);
SolutionType solution_type= milp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=milp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import static it.ssc.pl.milp.LP.NaN;
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.*;
import java.util.ArrayList;
public class Esempio {
public static void main(String[] args) throws Exception {
double A[][]={
{ 1.0 , 1.0 },
{ 1.0 , 1.4 },
{-5.0 , 3.0 },
{ 1.0 , 0.0 }, //definizione degli integer
{ 0.0 , 1.0 }, //definizione dei binary
{ 1.0 , 0.0 }, //definizione dei semicontinuous
{ 3.0 , NaN}, //definizione dei upper
{ 1.0 , 0.0 }, //definizione dei lower
} ;
double b[]= { 1.0, 6.0 ,5.0, NaN, NaN, NaN, NaN, NaN};
double c[]= { -1.0, 3.0 };
ConsType[] rel= {ConsType.GE, ConsType.LE, ConsType.LE, ConsType.INT, ConsType.BIN,
ConsType.SEMICONT, ConsType.UPPER, ConsType.LOWER};
LinearObjectiveFunction f = new LinearObjectiveFunction(c, GoalType.MAX);
ArrayList< Constraint > constraints = new ArrayList< Constraint >();
for(int i=0; i < A.length; i++) {
constraints.add(new Constraint(A[i], rel[i], b[i]));
}
MILP lp = new MILP(f,constraints);
SolutionType solution_type=lp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=lp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.FormatTypeInput.FormatType;
import it.ssc.pl.milp.MILP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputString;
public class Esempio {
public static void main(String[] args) throws Exception {
String lp_sparse =
// TYPE COL_ ROW_ COEF
" MAX . costo . \n" +
" GE . row1 . \n" +
" LE . row2 . \n" +
" LE . row3 . \n" +
" UPPER . lim_sup . \n" +
" LOWER . lim_inf . \n" +
" INTEGER . var_int . \n" +
" BINARY . var_bin . \n" +
" SEMICONT . var_sc . \n" +
" . Y1 costo 1 \n" +
" . Y1 row1 1 \n" +
" . Y1 row2 1 \n" +
" . Y1 row3 -5 \n" +
" . Y1 lim_sup 1 \n" +
" . Y1 lim_inf -1 \n" +
" . Y1 var_bin 1 \n" +
" . Y2 costo -3 \n" +
" . Y2 row1 1 \n" +
" . Y2 row2 1.4 \n" +
" . Y2 row3 3 \n" +
" . Y2 lim_sup . \n" +
" . Y2 lim_inf 1 \n" +
" . Y2 var_int 1 \n" +
" . Y2 var_sc 1 \n" +
" . RHS row1 1 \n" +
" . RHS row2 6 \n" +
" . RHS row3 5 \n" ;
InputString lp_input = new InputString(lp_sparse);
lp_input.setInputFormat("TYPE:varstring(8), COL_:varstring(3) , ROW_:varstring(7), COEF:double");
MILP milp = new MILP(lp_input,FormatType.SPARSE);
SolutionType solution_type=milp.resolve();
if(solution_type==SolutionType.OPTIMUM) {
Solution solution=milp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import it.ssc.context.exception.InvalidSessionException;
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.*;
import it.ssc.pl.milp.util.MILPThreadsNumber;
import static it.ssc.pl.milp.LP.NaN;
import java.util.ArrayList;
public class Esempio {
public static void main(String arg[]) throws InvalidSessionException, Exception {
double[] c = { 2, 2, 2, 2, 2 , 2, 2, 2, 2, 2, 2 ,2 , 2 };
double[] b = {1000, 1234, 1000, 1000, 1000, 1000, 1000, 1000, 1000};
double[][] A ={ { 2., 9. ,7. ,5. ,9. ,6. ,3., 7., 8. ,7. ,5. ,3. ,1. },
{ 4. ,1. ,2. ,3. ,6. ,4. ,5. ,2. ,8. ,5. ,3. ,4., 7. },
{ 3. ,4. ,2. ,5. ,7. ,6. ,3. ,5. ,7. ,4. ,6. ,8. ,6. },
{ 4. ,6. ,9. ,8. ,7. ,6. ,5. ,4. ,3. ,2. ,3. ,5. ,6. },
{ 4. ,4. ,7. ,5. ,3. ,8. ,5. ,6. ,3. ,5. ,6. ,4. ,6. },
{ 2. ,6. ,4. ,5. ,7. ,5. ,6. ,4. ,6. ,7. ,4. ,4. ,6. },
{ 4. ,6. ,9. ,8. ,3. ,6. ,5. ,5. ,3. ,2. ,9. ,5. ,6. },
{ 4. ,5. ,7. ,8. ,3. ,8. ,3. ,6. ,3. ,5. ,6. ,1. ,6. },
{ 2., 2., 4., 3., 7. ,5. ,9. ,4. ,6. ,7. ,8. ,4., 6. }};
double[] integer ={ 1.0, 1.0, 1.0, 1.0, 1.0 ,1.0 ,1.0 ,1.0 ,1.0 ,1.0 ,1.0 ,1.0, 1.0 };
LinearObjectiveFunction f = new LinearObjectiveFunction(c, GoalType.MAX);
ArrayList< Constraint > constraints = new ArrayList< Constraint >();
for(int i=0; i< A.length; i++) {
constraints.add(new Constraint(A[i], ConsType.LE, b[i]));
}
constraints.add(new Constraint(integer, ConsType.INT , NaN));
MILP milp = new MILP(f,constraints);
milp.setThreadNumber(MILPThreadsNumber.N_4);
SolutionType solutionType=milp.resolve();
if(solutionType==SolutionType.OPTIMUM) {
Solution solution=milp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore ottimo:"+solution.getOptimumValue());
}
}
}
import it.ssc.log.SscLogger;
import it.ssc.pl.milp.MILP;
import it.ssc.pl.milp.Solution;
import it.ssc.pl.milp.SolutionType;
import it.ssc.pl.milp.Variable;
import it.ssc.ref.InputString;
public class Esempio2_bix {
public static void main(String[] args) throws Exception {
String milp_string=
"-2 -1 min ." +"\n"+
"-1 -1 ge -5" +"\n"+
"1 -1 ge 0" +"\n"+
"-6 -2 ge -21" +"\n"+
"4 3 upper ." +"\n"+
"1 1 integer ." +"\n" ;
InputString milp_input = new InputString(milp_string);
milp_input.setInputFormat("X1-X2:double, TYPE:varstring(20), RHS:double");
MILP milp=new MILP(milp_input);
milp.setJustTakeFeasibleSolution(true);
SolutionType solution_type= milp.resolve();
if(solution_type==SolutionType.FEASIBLE) {
Solution solution=milp.getSolution();
for(Variable var:solution.getVariables()) {
SscLogger.log("Nome variabile :"+var.getName() + " valore:"+var.getValue());
}
SscLogger.log("Valore soluzione sulla f.o.:"+solution.getOptimumValue());
}
}
}
Per risolvere questo problema con SSC basta creare del testo dove ciascun rigo rappresenta o la funzione obiettivo o un vincolo, mentre le colonne rappresentano i coefficienti delle variabili, le relazioni, i valori rhs [righi 14-17 del codice sottostante]. Questa rappresentazione è denominata a coefficienti.
Formulato il problema occorre specificare il suo tracciato record (o formato di input). Per formato di input intendiamo una dichiarazione che descrive come vanno lette ed interpretate le colonne presenti nel testo in cui si è formulato il problema [righi 14-17]. La definizione del formato di input si effettuata attraverso una stringa da passare come argomento al metodo setInputFormat() [rigo 21]; in questa stringa si susseguono le notazioni "nome colonna : tipologia colonna" per definire, in sequenza, il nome ed il tipo delle colonne. In definitiva si dichiarano: i nomi delle prime due colonne che rappresentano le variabili del problema di LP (in questo caso X1 e X2, di tipo numerico double), la colonna delle relazioni (chiamata TYPE e di tipo stringa), la colonna dei valori rhs (chiamata RHS e di tipo double). I nomi da assegnare alle variabili del problema di LP possono essere qualsiasi, mentre la colonna delle relazioni e quella dei valori rhs devono necessariamente chiamarsi TYPE e RHS [rigo 21].
Di norma possiamo chiamare le variabili in qualsiasi modo, anche con nomi non necessariamente seguiti da un numero, ad esempio : "FUEL:double, AMOUNT:double, WEIGHT:double", etc, etc. Di solito però è preferibile dichiarare le n variabili di un problema con una diversa notazione, chiamata ad intervalli, che risulta particolarmente utile se le variabili del problema sono decine o centinaia. In questo caso la dichiarazione "X1:double, X2:double, X3:double, .... , Xn:double" di n variabili, può essere sostituita con la notazione "X1-Xn:double". Questa seconda notazione, certamente più compatta, permette di dichiarare tutte le variabili comprese nell'intervallo che va da X1 a Xn.
Una volta rappresentato il problema e assegnati i nomi alle variabili, si esegue l'algoritmo del Simplesso mediante la creazione di un oggetto della classe LP e l'invocazione del metodo resolve() [righi 23-24]. Una volta eseguito il Simplesso, il metodo resolve() ritorna il tipo di soluzione trovata; se la soluzione è ottima è possibile ricavare i valori delle variabili ed il valore ottimo della funzione obiettivo. Si ricorda che in SSC, di default, le variabili di un problema di LP sono considerate, se non diversamente specificato, non negative ( ≥ 0).