Skip to content

Instantly share code, notes, and snippets.

View chrispahm's full-sized avatar
🌻
https://fruchtfolge.agp.uni-bonn.de/

Christoph Pahmeyer chrispahm

🌻
https://fruchtfolge.agp.uni-bonn.de/
View GitHub Profile
@chrispahm
chrispahm / branchAndCut.js
Created April 4, 2017 21:01
acceptableThreshold Definition
// Current implementation:
// The variable bestPossibleEval will be equal to the evaluation of the first simplex iteration
// displaying the best possible solution to the problem.
// The while loop will now be terminated if the current bestEvaluation is smaller (due to negtaive sign)
// than the acceptableThreshold -> supposed to be the way its done in GAMS
while (branches.length > 0 && toleranceFlag === true) {
var acceptableThreshold = this.bestPossibleEval * (1 - (tolerance/100));
// Abort while loop if termination tolerance is both specified and condition is met
if (tolerance > 0) {
/*
Vorgewende
API Methods
lineString (poly, (angle), (distance)) - Returns array consisting of a GeoJSON lineString for each headland for the given field
Polygon (poly, workingWidth, (angle), (distance))- Returns an array consisting of a GeoJSON Polygon for each headland using the working width as its width for the given field
*/
const GJV = require("geojson-validation")
const turf = require('@turf/turf')
module.exports = {
/*
Vorgewende
API Methods
lineString (poly, (angle), (distance)) - Returns array consisting of a GeoJSON lineString for each headland for the given field
Polygon (poly, workingWidth, (angle), (distance))- Returns an array consisting of a GeoJSON Polygon for each headland using the working width as its width for the given field
*/
const GJV = require("geojson-validation")
const turf = require('@turf/turf')
module.exports = {
var resizedPoly = turf.transformScale(polygon, 1000)
Draw.add(resizedPoly)
Draw.add(turf.simplify(resizedPoly, {tolerance: 0.05, highQuality: true}))
Draw.add(turf.simplify(resizedPoly, {tolerance: 0.4, highQuality: true}))
vorgewende.lineString(turf.simplify(resizedPoly, {tolerance: 0.05, highQuality: true}),38)
map.fitBounds(turf.bbox(resizedPoly))
@chrispahm
chrispahm / init.coffee
Last active February 19, 2018 09:35
Init script to run GAMS file through Atom command palette
# GAMS run init script
#
# This atom init script will execute the current GAMS file
# and subsequently open the according listing (.lst) file
# An example hack to log to the console when each text editor is saved.
# You would need to have linter-gams installed and adjust the below filepaths
# to your needs
atom.commands.add 'atom-text-editor', 'gams:run', =>
return unless editor = atom.workspace.getActiveTextEditor()
/*************************************************************
* Method: reformatGAMS
* Scope: Public:
* Agruments: model: The model we want solver to operate on
optcr: Termination tolerance
* Purpose: Convert a friendly JSON model into a model for a
* real solving library...in this case
* GAMS
**************************************************************/
// this.reformatGAMS = function (model, optcr) {
/*************************************************************
* Method: lstParse
* Scope: Public:
* Agruments: listingFile: The GAMS listingFile file to interpreted
model: The model we want solver to operate on
* Purpose: Convert the results of a GAMS CPLEX solve to a
* friendly JSON similar to the one generated by
* the jsLPsolver
**************************************************************/
// Check model status, and only proceed if status code is in modelStatus-Array
@chrispahm
chrispahm / show_params_currently_in_gms_model.js
Created August 9, 2019 12:52
Find out all active parameters currently used in a GAMS model (using Atom linter-gams)
// open the developer console in Atom (ctrl-shift-i on Windows)
// and paste the following code in order to get a list of all
// active parameters currently used in the GAMS model
global.gamsView.filter(elem => {
function checkRef(ref) {
let flag = false
ref.forEach(ref => {
if (ref.file.includes('templ.gms') || ref.file.includes('model')) flag = true
})
return flag
@chrispahm
chrispahm / optimise-images-terminal.md
Last active August 18, 2019 10:41 — forked from gielcobben/optimise-images-terminal.md
Optimise your pngs from the terminal in OSX

JPG:
$ brew install jpegoptim
$ mkdir lowRes
$ sips -Z 1024 *.jpg --out lowRes
$ cd lowRes
$ find . -name "*.jpg" -exec jpegoptim -m80 -o -p --strip-all {} \;

- PNG:
$ brew install optipng
$ mkdir lowRes

@chrispahm
chrispahm / gist:4804fd4e22cd0fbd293f659530c2271d
Last active September 27, 2019 13:37
R lm() poly output to JS function
var coeff = [
[1,0],
[2,0],
[3,0],
[4,0],
[0,1],
[1,1],
[2,1],
[3,1],
[0,2],