@@ -18,68 +18,44 @@ object runner {
1818 import AccountRates ._
1919 import Income ._
2020 println(" Initializing" )
21- val starterAccounts = Accounts (Seq (CheckingAccount (1 ,30000 ),BokerageAccount (2 ,60000 )),Seq ())
22- val rentPeriod = dates(Month (LocalDate .now()),LocalDate .now().plusYears(20 ))
23- val starterProperties = Properties (Seq (RentalProperty (1 ,1300 ,rentPeriod)),Seq ())
24- val startingDate = Month (LocalDate .now())
25- val incomemeta = Seq (
26- ficaTaxableincome(1 ,3500 ,1 ,dates(Month (LocalDate .now()),LocalDate .now().plusYears(10 ),Seq ())),
27- ficaTaxableincome(2 ,500 ,1 ,dates(Week (LocalDate .now().plusMonths(6 )),LocalDate .now().plusYears(2 ),Seq ())),
28- ficaTaxableincome(3 ,5500 ,1 ,dates(Year (LocalDate .now()),LocalDate .now().plusYears(10 ),Seq ())),
29- ficaTaxableincome(4 ,1500 ,1 ,dates(Month (LocalDate .now().plusYears(1 )),LocalDate .now().plusYears(10 ),Seq ()))
30- )
31- val incomes = Incomes (incomemeta)
21+
3222 type ProgramDependencies =
3323 Accounts with
3424 AccountRates with
3525 Properties with
3626 Date with
3727 Incomes
3828
39- val dat : dataset[ProgramDependencies ] = data[ProgramDependencies ]()
40- // define start data
41- .++ [Date ,Month ](startingDate)++
42- starterAccounts ++
43- AccountRates (0.67 ,0.01 ,0.06 ) ++
44- incomes ++
45- starterProperties +-
46- Prog (1000000 )
47- // include the program we want to loop over
48- // if we dont' want to build an implicit grammar for it
4929
50- def main (args : Array [String ]): Unit = {
51- val start = System .currentTimeMillis()
52- // run base loop
53- val res = dat.toWeeklyCadence.solve[Prog ].properties.events.sortWith((a,b) => a.date.isBefore(b.date))// .get.get(3).value//.events.filter(_.incomeId == 1)
54- println(res)
55- val end = System .currentTimeMillis()
56- println(s " time elapsed: ${end - start} milliseconds " )
57- }
58- case class Prog (limit: Double ) extends (ProgramDependencies ==> ProgramDependencies ) with solveable[ProgramDependencies ] {
30+ // //////////////////////////////////
31+ // define our top level simulation
32+ case class Prog (limit: Double )
33+ extends (ProgramDependencies ==> ProgramDependencies )
34+ with solveable[ProgramDependencies ] {
5935 override def apply (src : dataset[ProgramDependencies ]): dataset[ProgramDependencies ] = for {
6036 date <- src.currentDate
6137 }yield {
6238 date match {
6339 case _:Month | _:Week =>
6440 src
65- .growAccounts
66- .accrueRent
67- .receiveIncomes
68- .payRents
69- .nextPeriod
41+ .growAccounts
42+ .accrueRent
43+ .receiveIncomes
44+ .payRents
45+ .nextPeriod
7046 case y: Year =>
7147 (0 until 12 ).foldLeft(src)((src_,_) =>
7248 src_
7349 .toMonthlyCadence
74- .runSim
50+ .runSim
7551 ).toYearlyCadence
7652 }
7753 }
7854
7955 override def solved (src : dataset[ProgramDependencies ]): Boolean =
8056 (src
81- .underlyingAccounts.exists) &&
82- src.underlyingAccounts
57+ .underlyingAccounts.exists) &&
58+ src.underlyingAccounts
8359 .value
8460 .map(_.balance)
8561 .sum > limit
@@ -88,10 +64,49 @@ object runner {
8864 src.runSim
8965 )
9066 }
67+ // //////////////////////////////
68+ // define implicit grammar for sim
9169 import scala .reflect .runtime .universe .TypeTag
9270 implicit class RunSim [A <: ProgramDependencies ](src: dataset[A ])(implicit taga: TypeTag [A ]){
9371 def runSim : dataset[A ] = src.+- (Prog (10000000 )).--> [Prog ]
9472 }
9573
74+ // ///////////////////////////////////////////////////////////
75+ // /////////Define Starting Data/////////////////////////////
76+ val starterAccounts = Accounts (Seq (CheckingAccount (1 ,30000 ),BokerageAccount (2 ,60000 )),Seq ())
77+ val rentPeriod = dates(Month (LocalDate .now()),LocalDate .now().plusYears(20 ))
78+ val starterProperties = Properties (Seq (RentalProperty (1 ,1300 ,rentPeriod)),Seq ())
79+ val startingDate = Month (LocalDate .now())
80+ val incomemeta = Seq (
81+ ficaTaxableincome(1 ,3500 ,1 ,dates(Month (LocalDate .now()),LocalDate .now().plusYears(10 ),Seq ())),
82+ ficaTaxableincome(2 ,500 ,1 ,dates(Week (LocalDate .now().plusMonths(6 )),LocalDate .now().plusYears(2 ),Seq ())),
83+ ficaTaxableincome(3 ,5500 ,1 ,dates(Year (LocalDate .now()),LocalDate .now().plusYears(10 ),Seq ())),
84+ ficaTaxableincome(4 ,1500 ,1 ,dates(Month (LocalDate .now().plusYears(1 )),LocalDate .now().plusYears(10 ),Seq ()))
85+ )
86+ val incomes = Incomes (incomemeta)
87+ val dat : dataset[ProgramDependencies ] = data[ProgramDependencies ]()
88+ // include initial data
89+ .++ [Date ,Month ](startingDate)++
90+ starterAccounts ++
91+ AccountRates (0.67 ,0.01 ,0.06 ) ++
92+ incomes ++
93+ starterProperties +-
94+ // include the program we want to loop over
95+ // if we dont' want to build an implicit grammar for it
96+ Prog (1000000 )
97+
98+
99+ def main (args : Array [String ]): Unit = {
100+ val start = System .currentTimeMillis()
101+ // run solve baseLoop for solve condition
102+ val res = dat.toWeeklyCadence.solve[Prog ]
103+ .properties
104+ .events
105+ .sortWith((a,b) => a.date.isBefore(b.date))
106+ println(res)
107+ val end = System .currentTimeMillis()
108+ println(s " time elapsed: ${end - start} milliseconds " )
109+ }
110+
96111
97112}
0 commit comments