Skip to content

Instantly share code, notes, and snippets.

View felixlindemann's full-sized avatar

Felix Lindemann felixlindemann

  • Lime-Tree
  • Wuppertal, Germany
View GitHub Profile
@felixlindemann
felixlindemann / gist:12a0ee02eb34b9ad6c99
Created December 18, 2014 09:39
lime-tree Test 01: Default.aspx
<article>
<table>
<tr>
<th>
<asp:Label ID="Label1" runat="server" Text="Sugarlevel">
</asp:Label>
</th>
<td>
<asp:TextBox ID="sugarlevel" ToolTip="Hit Enter to update" runat="server" Width="140px"></asp:TextBox >
@felixlindemann
felixlindemann / example.r
Last active August 29, 2015 14:10
example
# install.packages("shape") # in case shape is not installed
require(shape)
# install.packages("plotrix") # in case plotrix is not installed
require(plotrix)
##################################################################################################################################
##################################################################################################################################
############################################# Helper functions #################################################################
##################################################################################################################################
##################################################################################################################################
@felixlindemann
felixlindemann / helpers.r
Created December 4, 2014 14:06
vrp-plot helpers
plottitle <- function(t){
### Plot "Folie ###"
plot(NA,NA,frame.plot=FALSE, xlab="", ylab="", xlim= c(-1,1), ylim=c(-1,1), axes=FALSE)
text(0,0,t, cex=2, )
}
getPolar <- function(n0,n1){
# Polarwinkel berechnung zum vekürzen der Pfeile
x1 <- n1$x
@felixlindemann
felixlindemann / getNumberOfStops.r
Created December 4, 2014 14:05
Calculate the fitnes of the rout: number of stops in a genetic algorithm
getNumberOfStops <- function(tour){
# wieviele Stops führen zum Depot zurück?
n <- which(tour==1) # 1=depot
return (length(n))
}
@felixlindemann
felixlindemann / calcTourplan.r
Created December 4, 2014 14:02
calculate fitnes of a tourplan in a genetic algorithm
calcTourplan <- function(cij, tour){
F <- 0
# Speichere die Orte, die keinen Vorgänger haben --> Also vom Depot aus angesteuert werden
hasPreDecessor <- rep(FALSE, nrow(locations))
for(i in 1:ncol(tour)){
F<- F + cij[i+1, tour[i]]
hasPreDecessor[tour[i]] <- TRUE
@felixlindemann
felixlindemann / mutate.r
Created December 4, 2014 13:53
Mutation process with in a genetic algorithm
# mutation
mutate <- function(tour){
# suche zufällig einen Start knoten aus, der mit einem Endknoten verbunden wird.
# combine which stop o[1] with wich stop o[2]
o <- sample(1:length(tour), 2)
tour[o[1]] <- o[2] + 1 # 1 is depot
# mutated tour
#immediate Repair
@felixlindemann
felixlindemann / repair2.r
Created December 4, 2014 13:49
Repair short cycles in a genetic algorithm
repair2 <- function(tour){
#repair short cycles (DFJc)
# iteriere über jeden Stop im Tourenplan
for(i in 1:length(tour)){
# wenn der Nachfolger nicht das Depot ist (hier index = 1)
# dann kann es Kurzzyklen geben
if(tour[i]>1){ # not returning to depot
@felixlindemann
felixlindemann / searchFor.r
Created December 4, 2014 13:48
Recursive function for a genetic algorithm to find short cycles
searchFor <- function(tour, index, start){
#helper function für recursiven Aufruf
if(tour[index -1] == 1) # 1 == depot
{
return(TRUE)
}else{
if(tour[index -1] == start) # Kurzzyklus gefunden
{
return(FALSE)
@felixlindemann
felixlindemann / repair1.r
Created December 4, 2014 13:38
Repair child according to cond 1&2 in a #Genetic Algortihm
repair1 <- function(tour){
#cond 1/2 once arrive/leave
#substitute multiple indices by 0(1) --> ALL!
#getunique stops
y<-unique(tour)
y<- y[y!=1] # 1 --> 0 # elminate Depot-Stops
#iterate over potentail multiple Stop indices
@felixlindemann
felixlindemann / recombine.r
Created December 4, 2014 13:03
Recombine Tours within a Genetic Algorithm
recombine<- function(tours, f, m, recomb){
# tours = Genpool
# f = father index
# m = mother index
# recomb = Predefined Recombination vector
t.f <- tours[f,] #get tourplan father
t.m <- tours[m,] #get tourplan mother
t.c <- t.f # use father as template