[jboss-svn-commits] JBL Code SVN: r16765 - in labs/jbossrules/contrib/benchmarks/src/rules/benchmarks: dispatch and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Nov 23 13:39:14 EST 2007
Author: shabino
Date: 2007-11-23 13:39:14 -0500 (Fri, 23 Nov 2007)
New Revision: 16765
Added:
labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/
labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Derivations.dslr
labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/EligibilityExclusions.dslr
labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/LogicalTopTier.dslr
labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Queries.drl
labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/ScoreManagement.dslr
labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Scoring.dslr
labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/WorkerEligibility.dslr
labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/dispatch.dsl
Log:
initial commit of dispatch benchmark
Added: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Derivations.dslr
===================================================================
--- labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Derivations.dslr (rev 0)
+++ labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Derivations.dslr 2007-11-23 18:39:14 UTC (rev 16765)
@@ -0,0 +1,132 @@
+package dispatch
+
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import benchmarks.dispatch.fact.derived.*
+import benchmarks.dispatch.fact.independent.*
+import java.util.Date
+
+import function benchmarks.dispatch.function.Helper.distanceToPickupInMiles
+import function benchmarks.dispatch.function.Helper.minutesLateToJob
+import function benchmarks.dispatch.function.Helper.minutesBetweenDates
+
+expander dispatch.dsl
+
+rule "Time Available for Job when not on job"
+ when
+ w : Worker(status != Worker.Status.DISPATCHED_FOR_JOB)
+ time matters
+ then
+ DateWorkerInfo workerInfo = new DateWorkerInfo(w.getWorkerId());
+ workerInfo.setType(WorkerInfo.Type.TIME_AVAILABLE_FOR_DISPATCH);
+ #If we just use system date, workers get stamped as available in the past
+ workerInfo.setValue(ds.getCurrentTime());
+ insertLogical(workerInfo);
+end
+
+rule "Time Available for Job when already on Job"
+ when
+ w : Worker(status == Worker.Status.DISPATCHED_FOR_JOB)
+
+ then
+ DateWorkerInfo workerInfo = new DateWorkerInfo(w.getWorkerId());
+ workerInfo.setType(WorkerInfo.Type.TIME_AVAILABLE_FOR_DISPATCH);
+ workerInfo.setValue(w.getTimeAvailable());
+ insertLogical(workerInfo);
+end
+
+rule "Position Available for job when not on job"
+ when
+ w : Worker(status != Worker.Status.DISPATCHED_FOR_JOB)
+ wp: WorkerPosition(workerId == w.workerId)
+ then
+ PositionWorkerInfo workerInfo = new PositionWorkerInfo(w.getWorkerId());
+ workerInfo.setType(WorkerInfo.Type.POSITION_AVAILABLE_FOR_DISPATCH);
+ workerInfo.setLatitude(wp.getLatitude());
+ workerInfo.setLongitude(wp.getLongitude());
+ insertLogical(workerInfo);
+end
+
+rule "Position Available for Dispatch When On Load"
+ when
+ w : Worker(status == Worker.Status.DISPATCHED_FOR_JOB)
+ then
+ PositionWorkerInfo workerInfo = new PositionWorkerInfo(w.getWorkerId());
+ workerInfo.setType(WorkerInfo.Type.POSITION_AVAILABLE_FOR_DISPATCH);
+ workerInfo.setLatitude(w.getCurrentJobLatitude());
+ workerInfo.setLongitude(w.getCurrentJobLongitude());
+ insertLogical(workerInfo);
+end
+
+rule "Distance to job"
+ when
+ j : Job()
+ job dispatchable
+ w: Worker()
+ dvi: PositionWorkerInfo(workerId == w.workerId, type == WorkerInfo.Type.POSITION_AVAILABLE_FOR_DISPATCH)
+ then
+ Double dist = distanceToPickupInMiles(j, dvi.getLatitude(), dvi.getLongitude());
+ DecimalInfo i = new DecimalInfo(j, w);
+ i.setValue(dist * 1.3);
+ i.setType(Info.Type.DISTANCE_TO_JOB_MILES);
+ insertLogical(i);
+end
+
+rule "Time to get to job"
+ when
+ j : Job()
+ job dispatchable
+ w: Worker()
+ i: DecimalInfo(jobId == j.jobId, workerId == w.workerId, type == Info.Type.DISTANCE_TO_JOB_MILES)
+ then
+ DecimalInfo ti = new DecimalInfo(j, w);
+ ti.setType(Info.Type.TIME_TO_JOB_MINUTES);
+ #Presume 45 MPH
+ ti.setValue((Double)i.getValue() / 45 * 60);
+ insertLogical(ti);
+end
+
+rule "Minutes Late to Job"
+ when
+ j : Job()
+ job dispatchable
+ w: Worker()
+ availDate: DateWorkerInfo(workerId == w.workerId, type == WorkerInfo.Type.TIME_AVAILABLE_FOR_DISPATCH)
+ timeToJob: DecimalInfo(jobId == j.jobId, workerId == w.workerId, type == Info.Type.TIME_TO_JOB_MINUTES)
+ then
+ DecimalInfo ti = new DecimalInfo(j ,w);
+ ti.setType(Info.Type.MINUTES_LATE_TO_JOB);
+
+ ti.setValue(minutesLateToJob(j.getStartTime(), availDate.getValue(), timeToJob.getValue()));
+ insertLogical(ti);
+end
+
+rule "Age of Worker Position"
+ when
+ j: Job()
+ job dispatchable
+ w : Worker()
+ time matters
+ #Only compute if position too old
+ wp : WorkerPosition(workerId == w.workerId, positionObservationDate < ds.positionCutOff)
+ then
+ DecimalInfo ti = new DecimalInfo(j ,w);
+ ti.setType(Info.Type.WORKER_POSITION_AGE_MINUTES);
+ ti.setValue(minutesBetweenDates(wp.getPositionObservationDate(), ds.getPositionCutOff()));
+ insertLogical(ti);
+end
+
Property changes on: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Derivations.dslr
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/EligibilityExclusions.dslr
===================================================================
--- labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/EligibilityExclusions.dslr (rev 0)
+++ labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/EligibilityExclusions.dslr 2007-11-23 18:39:14 UTC (rev 16765)
@@ -0,0 +1,37 @@
+package dispatch
+
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import benchmarks.dispatch.fact.derived.*
+import benchmarks.dispatch.fact.independent.*
+
+expander dispatch.dsl
+
+rule "Retract Eligibility if job too far in future"
+ salience 300
+ when
+ time matters
+ #We refuse to waste cycles on jobs far in the future
+ #However, because the rules engine only gets a delta feed,
+ #It is possible that a job might require consideration
+ #later w/o reassertion. Therefore, we can't retract the fact
+ j : Job(startTime > ds.startTimeCutOff)
+ then
+ JobExclusion je = new JobExclusion();
+ je.setJobId(j.getJobId());
+ insertLogical(je);
+end
\ No newline at end of file
Property changes on: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/EligibilityExclusions.dslr
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/LogicalTopTier.dslr
===================================================================
--- labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/LogicalTopTier.dslr (rev 0)
+++ labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/LogicalTopTier.dslr 2007-11-23 18:39:14 UTC (rev 16765)
@@ -0,0 +1,50 @@
+package dispatch
+
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import benchmarks.dispatch.fact.derived.*
+import benchmarks.dispatch.fact.independent.*
+import java.util.Date
+
+expander dispatch.dsl
+
+rule "Clobber inactive (terminated) workers"
+ salience 400
+ when
+ w: Worker(status == Worker.Status.INACTIVE)
+ then
+ retract(w);
+end
+
+rule "Clobber dispatched jobs"
+ salience 400
+ when
+ j: Job(status != Job.Status.PENDING)
+ then
+ retract(j);
+end
+
+
+
+rule "Clobber dead positions"
+ salience 200
+ when
+ wp: WorkerPosition()
+ not Worker(workerId == wp.workerId)
+ then
+ retract(wp);
+end
Property changes on: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/LogicalTopTier.dslr
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Queries.drl
===================================================================
--- labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Queries.drl (rev 0)
+++ labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Queries.drl 2007-11-23 18:39:14 UTC (rev 16765)
@@ -0,0 +1,24 @@
+package dispatch
+
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import benchmarks.dispatch.fact.derived.*
+import benchmarks.dispatch.fact.independent.*
+
+query getTopWorkersForJob (String s)
+ e: TopWorkers(jobId == s)
+end
Property changes on: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Queries.drl
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/ScoreManagement.dslr
===================================================================
--- labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/ScoreManagement.dslr (rev 0)
+++ labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/ScoreManagement.dslr 2007-11-23 18:39:14 UTC (rev 16765)
@@ -0,0 +1,76 @@
+package dispatch
+
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import benchmarks.dispatch.fact.derived.*
+import benchmarks.dispatch.fact.independent.*
+import java.util.Date
+import java.util.Set
+
+expander dispatch.dsl
+
+rule "Default Score Component"
+salience -25
+when
+ #Force score accumulation if no score components
+ j : Job()
+ job dispatchable
+ w: Worker()
+ #Don't score workers that aren't eligible
+ not Exclusion(workerId == w.workerId, jobId == j.jobId)
+then
+ ScoreComponent sc = new ScoreComponent(j, w);
+ sc.setType(ScoreComponent.Type.DEFAULT);
+ sc.setContribution(0D);
+ insertLogical(sc);
+end
+
+rule "Accumulate Score"
+salience -50
+when
+ j : Job()
+ job dispatchable
+ w: Worker()
+ #Don't score workers that aren't eligible
+ not Exclusion(workerId == w.workerId, jobId == j.jobId)
+ totScore : Double()
+ from accumulate( ScoreComponent( workerId == w.workerId, jobId == j.jobId, sc:contribution ),
+ sum(sc) )
+then
+ Score s = new Score(j, w);
+ s.setScore(totScore);
+ insertLogical(s);
+end
+
+
+rule "Accumulate Top Workers"
+salience -100
+when
+ j : Job()
+ job dispatchable
+ scoreList : Set()
+ from accumulate( s: Score(jobId == j.jobId),
+ top_workers(s)
+ )
+then
+ TopWorkers topWorkers = new TopWorkers();
+ topWorkers.setJobId(j.getJobId());
+ for (Object s: scoreList){
+ topWorkers.getTopWorkers().add(((Score)s).getWorkerId());
+ }
+ insertLogical(topWorkers);
+end
Property changes on: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/ScoreManagement.dslr
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Scoring.dslr
===================================================================
--- labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Scoring.dslr (rev 0)
+++ labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Scoring.dslr 2007-11-23 18:39:14 UTC (rev 16765)
@@ -0,0 +1,55 @@
+package dispatch
+
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import benchmarks.dispatch.fact.derived.*
+import benchmarks.dispatch.fact.independent.*
+import java.util.Date
+
+expander dispatch.dsl
+
+rule "Distance to Job Score"
+ when
+ j: Job()
+ job dispatchable
+ w: Worker()
+ i: DecimalInfo(workerId == w.workerId, jobId == j.jobId,
+ type == Info.Type.DISTANCE_TO_JOB_MILES, dist: value >= 100)
+ then
+ ScoreComponent sc = new ScoreComponent(j, w);
+ sc.setType(ScoreComponent.Type.EXCESSIVE_DISTANCE_TO_JOB);
+ if (w.getVehicleSize() == VehicleSize.EXTRA_LARGE){
+ sc.setContribution(- 0.55 * (dist - 100));
+ } else {
+ sc.setContribution(- 0.4 * (dist - 100));
+ }
+ insertLogical(sc);
+end
+
+rule "Late to Job Score"
+ when
+ j : Job
+ job dispatchable
+ w : Worker()
+ i: DecimalInfo(jobId == j.jobId, workerId == w.workerId,
+ type == Info.Type.MINUTES_LATE_TO_JOB, minutesLate: value >= 0)
+ then
+ ScoreComponent sc = new ScoreComponent(j, w);
+ sc.setType(ScoreComponent.Type.LATE_TO_JOB);
+ sc.setContribution(- 400 - minutesLate * 0.2);
+ insertLogical(sc);
+end
\ No newline at end of file
Property changes on: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/Scoring.dslr
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/WorkerEligibility.dslr
===================================================================
--- labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/WorkerEligibility.dslr (rev 0)
+++ labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/WorkerEligibility.dslr 2007-11-23 18:39:14 UTC (rev 16765)
@@ -0,0 +1,62 @@
+package dispatch
+
+/*
+ * Copyright 2007 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import benchmarks.dispatch.fact.derived.*
+import benchmarks.dispatch.fact.independent.*
+import java.util.Date
+
+expander dispatch.dsl
+
+rule "Vehicle size must be sufficiently large"
+ when
+ j : Job(vs: vehicleSizeRequired.sizeNumber)
+ job dispatchable
+ w: Worker(vehicleSize.sizeNumber < vs)
+ then
+ ineligible because of VEHICLE_SIZE
+end
+
+rule "If the job requires a wrench, the worker must have a wrench"
+ when
+ j : Job(wrenchRequired == true)
+ job dispatchable
+ w : Worker(hasWrench == false)
+ then
+ ineligible because of WRENCH_REQUIRED
+end
+
+rule "If the job requires X sticks, the worker must have X sticks"
+ when
+ j : Job(req:numberOfSticksRequired)
+ job dispatchable
+ w : Worker(numberOfSticks < req)
+ then
+ ineligible because of NUM_STICKS
+end
+
+rule "If the job requires X rocks, the worker must have X rocks"
+ when
+ j : Job(req:numberOfRocksRequired)
+ job dispatchable
+ w : Worker(numberOfRocks < req)
+ then
+ ineligible because of NUM_ROCKS
+end
+
+
+
Property changes on: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/WorkerEligibility.dslr
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/dispatch.dsl
===================================================================
--- labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/dispatch.dsl (rev 0)
+++ labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/dispatch.dsl 2007-11-23 18:39:14 UTC (rev 16765)
@@ -0,0 +1,4 @@
+[*][]{anything}={anything}
+[consequence][]ineligible because of {condition}=Exclusion e = new Exclusion(j, w); e.setType(Exclusion.Type.{condition});insertLogical(e);
+[condition][]time matters=ds: DispatchState()
+[condition][]job dispatchable=not JobExclusion(jobId == j.jobId)
Property changes on: labs/jbossrules/contrib/benchmarks/src/rules/benchmarks/dispatch/dispatch.dsl
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list