1package com.gams.examples.clad;
3import java.io.BufferedWriter;
4import java.io.ByteArrayOutputStream;
6import java.io.FileWriter;
7import java.io.PrintStream;
8import java.util.AbstractMap;
9import java.util.ArrayList;
34 public static void main(String[] args) {
39 File workingDirectory =
new File(System.getProperty(
"user.dir"),
"Clad");
40 workingDirectory.mkdir();
45 List<Map.Entry<Long,String>> steps =
new ArrayList<Map.Entry<Long,String>>();
46 steps.add(
new AbstractMap.SimpleEntry<Long, String>(
new Long(5),
"epgap 0.1" ) );
47 steps.add(
new AbstractMap.SimpleEntry<Long, String>(
new Long(10),
"epgap 0.2" ));
48 steps.add(
new AbstractMap.SimpleEntry<Long, String>(
new Long(20),
"epagap 1e9" ));
54 BufferedWriter outfile =
new BufferedWriter(
new FileWriter(logFile));
55 outfile.write(
"epgap 0"); outfile.newLine();
56 outfile.write(
"interactive 1"); outfile.newLine();
57 outfile.write(
"iafile cplex.op2"); outfile.newLine();
59 }
catch (Exception e) {
70 ByteArrayOutputStream os =
new ByteArrayOutputStream();
71 PrintStream ps =
new PrintStream(os);
73 Worker w =
new Worker(job, opt, ps);
77 for (Map.Entry<Long, String> entry : steps) {
78 long diffInSeconds = entry.getKey().longValue() - prevStep ;
80 System.out.println(
"** waiting "+ diffInSeconds * 1000+
" milliseconds");
81 w.join( diffInSeconds * 1000 );
82 }
catch( Exception e ) {
83 System.out.println(
"** Exception has been caught : "+e);
87 prevStep = entry.getKey().longValue();
90 BufferedWriter outfile =
new BufferedWriter(
new FileWriter(logFile));
91 outfile.write( entry.getValue() ); outfile.newLine();
93 }
catch (Exception e) {
98 System.out.println(
"** Interrupted Cplex to continue with new option: " + entry.getValue());
103 }
catch (InterruptedException e) { }
106 String log = os.toString();
107 if (!log.contains(
"Interrupted...")) {
108 System.out.println(
"** Solver log **");
109 System.out.println(log);
110 System.out.println();
111 System.out.println(
"** Expected the solver to be interrupted at least once.");
114 System.out.println(
"** Interrupted...");
119 static class Worker
extends Thread {
138 job.
run(option, output);
void setSolveLink(GAMSOptions.ESolveLink x)
void setSystemDirectory(String directory)
void setWorkingDirectory(String directory)
String workingDirectory()
GAMSJob addJobFromGamsLib(String modelName)
This example demonstrates how to implement a complex termination criterion for a difficult MIP using ...
Provides package namespace for Java interface and examples to General Algebraic Model System (GAMS).