diff --git a/GAMS/IntExtOpt.gms b/GAMS/IntExtOpt.gms new file mode 100644 index 0000000000000000000000000000000000000000..19eff5dad6163ae305d03130e20a7dada6bcfc02 --- /dev/null +++ b/GAMS/IntExtOpt.gms @@ -0,0 +1,70 @@ + + SET crop crop types including pasture / cereals, fruits, oilcrops, starchyRoots, treenuts, vegetables, pasture / + SET crop_less_pasture(crop) arable crops types includes treenuts but not pasture / cereals, fruits, oilcrops, starchyRoots, treenuts, vegetables / + SET feed_crop(crop) / cereals, oilcrops / + SET landuse land use type / cropland, pasture / + + PARAMETER previous_area(landuse) areas for previous timestep in ha + PARAMETER demand(crop) yield in t per ha + PARAMETER yield_ref(crop) yield in t per ha + +$gdxin %gdxincname% +$load previous_area, demand, yield_ref +$gdxin + + + PARAMETER + feedEnergy(crop) energy from feed in MJ per t + / cereals 1 + oilcrops 1.5 + pasture 0.4 + / ; + + SCALAR meatDemand /200/; + SCALAR meatEfficency /0.1/; + SCALAR maxLandUseChange /0.1/; + + VARIABLES + area(crop) total area for each crop + feedArea(crop) area used for feed for each crop + intensity(crop) intensity for each crop + yield(crop) energy per area for each crop + unit_energy(crop) energy per area for each crop + energy total input energy + ; + + POSITIVE VARIABLE area, intensity, feedArea; + + EQUATIONS + UNIT_ENERGY_EQ(crop) energy per area + YIELD_EQ(crop) yield given chosen intensity + CROP_DEMAND_CONSTRAINT(crop_less_pasture) satisfy demand for crop + MEAT_DEMAND_CONSTRAINT satisfy demand for crop + INTENSITY_CONSTRAINT(crop) intensity constraint + CROPLAND_CHANGE_CONSTRAINT constraint on the rate of land use change + PASTURE_CHANGE_CONSTRAINT constraint on the rate of land use change + AGRI_LAND_CHANGE_CONSTRAINT constraint expansion of agricultural land + ENERGY_EQ define objective function; + + UNIT_ENERGY_EQ(crop) .. unit_energy(crop) =E= intensity(crop) + intensity(crop) / 2 * intensity(crop) / 8; + + YIELD_EQ(crop) .. yield(crop) =E= yield_ref(crop) * intensity(crop); + + CROP_DEMAND_CONSTRAINT(crop_less_pasture) .. (area(crop_less_pasture) - feedArea(crop_less_pasture)) * yield(crop_less_pasture) =G= demand(crop_less_pasture); + + MEAT_DEMAND_CONSTRAINT .. meatEfficency*sum(feed_crop, feedEnergy(feed_crop) * feedArea(feed_crop) * yield(feed_crop)) + + feedEnergy('pasture') * area('pasture') * yield('pasture') =G= meatDemand; + + INTENSITY_CONSTRAINT(crop) .. intensity(crop) =G= 1; + + CROPLAND_CHANGE_CONSTRAINT .. abs(sum(crop_less_pasture, area(crop_less_pasture))/previous_area('cropland') - 1) =L= maxLandUseChange; + + PASTURE_CHANGE_CONSTRAINT .. abs(area('pasture')/previous_area('pasture') - 1) =L= maxLandUseChange; + + AGRI_LAND_CHANGE_CONSTRAINT .. abs(sum(crop, area(crop)) / sum(landuse, previous_area(landuse)) - 1) =L= maxLandUseChange; + + ENERGY_EQ .. energy =E= SUM(crop, area(crop)*unit_energy(crop)); + + MODEL LAND_USE /ALL/ ; + SOLVE LAND_USE USING DNLP MINIMIZING energy; + diff --git a/bin/ac/ed/lurg/GamsTest.class b/bin/ac/ed/lurg/GamsTest.class deleted file mode 100644 index 6e6d3546bd597db783ca2346c807837a05d1f0c3..0000000000000000000000000000000000000000 Binary files a/bin/ac/ed/lurg/GamsTest.class and /dev/null differ diff --git a/src/ac/ed/lurg/GamsTest.java b/src/ac/ed/lurg/GamsTest.java index 55e9345d4efa921f3ce7f269ea0e42e1f7305921..a62e52cb4c198628ea912bc22171ac5b09d73312 100644 --- a/src/ac/ed/lurg/GamsTest.java +++ b/src/ac/ed/lurg/GamsTest.java @@ -15,15 +15,13 @@ import com.gams.api.GAMSWorkspaceInfo; public class GamsTest { + private final static String WORKING_DIR = "/Users/peteralexander/Documents/R_Workspace/tempDir"; + public static void main(String[] args) { - - // create GAMSWorkspace "ws" with default working directory - // (the directory named with current date and time under System.getProperty("java.io.tmpdir")) - System.out.println(System.getProperty("user.dir")); - File workingDirectory = new File(System.getProperty("user.dir"), "GamsTest"); + + File workingDirectory = new File(WORKING_DIR, "GamsTest"); workingDirectory.mkdir(); - // create a workspace GAMSWorkspaceInfo wsInfo = new GAMSWorkspaceInfo(); wsInfo.setWorkingDirectory(workingDirectory.getAbsolutePath()); @@ -59,7 +57,6 @@ public class GamsTest { } // add a database and add input data into the database - GAMSParameter a = db.addParameter("previous_area", 1, "previous area"); for(String c : previous_area.keySet()) a.addRecord(c).setValue(previous_area.get(c)); @@ -73,7 +70,7 @@ public class GamsTest { y.addRecord(c).setValue(yield_ref.get(c)); // create GAMSJob "t2" from the "model" string variable - GAMSJob t2 = ws.addJobFromFile("/Users/peteralexander/Documents/R_Workspace/landalloc/GAMS/IntExtOpt.gms"); + GAMSJob t2 = ws.addJobFromFile("/Users/peteralexander/Documents/R_Workspace/UNPLUM/GAMS/IntExtOpt.gms"); GAMSOptions opt = ws.addOptions(); System.out.println(db.getName()); @@ -90,8 +87,6 @@ public class GamsTest { // cleanup GAMSWorkspace's working directory cleanup(ws.workingDirectory()); - // terminate program - System.exit(0); } static void cleanup(String directory) {