PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/farmR/R/CompositeFarm-class.R

https://code.google.com/p/javawfm/
R | 54 lines | 34 code | 11 blank | 9 comment | 8 complexity | 61a0cf0327f18ab84d13b1e5159db5cc MD5 | raw file
 1# Implementation of the Composite Farm class #
 2#
 3# Usually used to represent a farming enterprise using a weighted sum of solutions from 
 4# farms with different soiltypes, objective weights and/or distances to sugarbeet factories
 5#
 6####################################
 7
 8
 9################### Constructor #######################
10# Create a new Farm object from its economic parameters
11#######################################################
12CompositeFarm <- function(farmParams,mou=NULL,mouweights=c(1.0),soildata,SBFactories=NULL,haulagePerTonnePerKm=0.12,maxSBHaulageDistance=200) { 
13	farm=new("CompositeFarm")
14	farm@model=.jnew("jfm/r/CompositeFarmRepresentation")
15	rf=0
16	wt=c()
17	if ( length(soildata$X0.5) > 1 ){
18		rf=mean(soildata$RF)
19		wt=c(mean(soildata$X0.5),mean(soildata$X0.75),mean(soildata$X1.0),mean(soildata$X1.25),mean(soildata$X1.5),mean(soildata$X1.75),mean(soildata$X2.0),mean(soildata$X2.5))
20	} else {
21		rf=soildata$RF
22		wt=c(soildata$X0.5,soildata$X0.75,soildata$X1.0,soildata$X1.25,soildata$X1.5,soildata$X1.75,soildata$X2.0,soildata$X2.5)
23	}
24	sl=c(0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.5)
25	for( i in 1:length(sl)){
26		if ( wt[i] > 0){
27			if ( !is.list(mou)){
28				mou=list(mou)
29			}
30			for( m in 1:length(mou)){
31				sfarm=Farm(farmParams)
32				if ( !is.null(mou[[m]])){
33					set(sfarm,mou[[m]])
34				}
35				if ( !is.null(SBFactories) ){
36					set.sugarbeet(sfarm,coordinates(soildata),SBFactories,haulagePerTonnePerKm,maxSBHaulageDistance)
37				}
38				.jcall(model(farm),"V","addFarm",model(sfarm),sl[i],rf,wt[i]*mouweights[m])
39				rm(sfarm) # probably doesn't do much
40			}
41		}
42	}
43	farm@cropNames=.jcall(farm@model,"[Ljava/lang/String;","cropNames")
44	farm
45}
46
47
48
49
50
51
52
53
54