annotate src/main/gov/nasa/jpf/vm/choice/PermutationCG.java @ 11:ca88bd8e918c

PairPermutationGenerator didn't have public ctor PermutationCG ctor didn't have id
author Peter Mehlitz <pcmehlitz@gmail.com>
date Wed, 25 Feb 2015 13:03:40 -0800
parents d0a0ff1c0e10
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
1 /*
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
2 * Copyright (C) 2015, United States Government, as represented by the
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
3 * Administrator of the National Aeronautics and Space Administration.
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
4 * All rights reserved.
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
5 *
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
8 * in compliance with the License. You may obtain a copy of the License at
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
9 *
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
10 * http://www.apache.org/licenses/LICENSE-2.0.
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
11 *
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
12 * Unless required by applicable law or agreed to in writing, software
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
13 * distributed under the License is distributed on an "AS IS" BASIS,
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
15 * See the License for the specific language governing permissions and
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
16 * limitations under the License.
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
17 */
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
18 package gov.nasa.jpf.vm.choice;
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
19
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
20 import gov.nasa.jpf.util.PermutationGenerator;
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
21 import gov.nasa.jpf.vm.ChoiceGeneratorBase;
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
22
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
23 /**
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
24 * a CG that creates permutation choices
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
25 *
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
26 * since PermutationCGs have a potentially huge number of choices, we don't
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
27 * compute and store them upfront, but rather keep the enumeration state in a
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
28 * low level pull-based generator
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
29 */
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
30 public class PermutationCG extends ChoiceGeneratorBase<int[]>{
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
31
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
32 protected PermutationGenerator pg;
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
33 protected int[] permutation;
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
34
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
35 public PermutationCG (PermutationGenerator pg){
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
36 this.pg = pg;
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
37 }
11
ca88bd8e918c PairPermutationGenerator didn't have public ctor
Peter Mehlitz <pcmehlitz@gmail.com>
parents: 4
diff changeset
38
ca88bd8e918c PairPermutationGenerator didn't have public ctor
Peter Mehlitz <pcmehlitz@gmail.com>
parents: 4
diff changeset
39 public PermutationCG (String id, PermutationGenerator pg){
ca88bd8e918c PairPermutationGenerator didn't have public ctor
Peter Mehlitz <pcmehlitz@gmail.com>
parents: 4
diff changeset
40 super(id);
ca88bd8e918c PairPermutationGenerator didn't have public ctor
Peter Mehlitz <pcmehlitz@gmail.com>
parents: 4
diff changeset
41 this.pg = pg;
ca88bd8e918c PairPermutationGenerator didn't have public ctor
Peter Mehlitz <pcmehlitz@gmail.com>
parents: 4
diff changeset
42 }
4
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
43
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
44 @Override
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
45 public int[] getNextChoice() {
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
46 return permutation;
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
47 }
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
48
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
49 @Override
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
50 public Class<int[]> getChoiceType() {
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
51 return int[].class;
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
52 }
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
53
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
54 @Override
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
55 public boolean hasMoreChoices() {
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
56 return pg.hasNext();
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
57 }
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
58
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
59 @Override
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
60 public void advance() {
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
61 permutation = pg.next();
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
62 }
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
63
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
64 @Override
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
65 public void reset() {
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
66 pg.reset();
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
67 }
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
68
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
69 @Override
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
70 public int getTotalNumberOfChoices() {
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
71 return (int) pg.getNumberOfPermutations();
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
72 }
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
73
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
74 @Override
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
75 public int getProcessedNumberOfChoices() {
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
76 return (int) pg.getNumberOfGeneratedPermutations();
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
77 }
d0a0ff1c0e10 added some infrastructure to pull-generate permutations (total, random and
Peter Mehlitz <pcmehlitz@gmail.com>
parents:
diff changeset
78 }