Вы находитесь на странице: 1из 11

STATIC CONSTRAINTS 


SOFT CONSTRAINTS 
­
Class c;
int a;//we can access it only after creating the obj.
Static int b;//we can access it without creating the 
obj.
endclass.
//hard constraints has to satisfy all the conditions 
else randomization fails.
//incase of soft constraints,randomization never 
fails ,even it was unable to satisfy the 
conditions,it just discards them.
SOFT CONSTRAINTS:
(THIS IS NOT A TYPE OF CONSTRAINT.) 
 The (normal) constraints described up to this point 
can be denoted as hard constraints because the 
solver must always satisfy them, or result in a solver 
failure. 
 In contrast, a constraint expression defined as soft 
designates a constraint that is to be satisfied unless 
contradicted by another constraint—either by a hard 
constraint or by a soft constraint with higher 
priority.
 Soft constraints are often used to specify default 
values and distributions for random variables.
EXAMPLE:
class Packet;

rand int length;

constraint deflt { soft length inside {32,1024}; }

endclass

Packet p = new();

p.randomize() with { length == 1512; }

//here is a conflict between two constraints.so it goes for priority 
between soft and hard contraints.Hard constarints will have the 
highest priority.inline constraint has the highest priority.
SOFT CONSTRAINTS PROPERTIES:
 Regular (hard) constraints has highest priority.
 Constraint expressions that appear later(latest) in the 
construct have higher priority.
 Constraint expressions in out­of­body constraint blocks whose 
prototypes appear later in the class have higher priority.
 class c
Extern c2//highest priority
Extern c1
Endclass
   constraint class name ::const_name{ ;   ;  }
   C2:: highest priority,as it was declared first in the class.
 Constraints in contained objects (rand class handles) have 
lower priority than all constraints in the container object (class 
or struct).
 Constraints in derived classes shall have higher priority than 
all constraints in their super classes.
SOFT CONSTRAINT PROPERTIES
 Constraints within in­line constraint blocks shall 
have higher priority than constraints in the class 
being randomized.
class B1;
rand int x;
constraint a { soft x > 10 ; soft x < 100 ; }
endclass  /* a1 */         /* a2 */
class D1 extends B1;
constraint b { soft x inside {[5:9]} ; }
endclass  /* b1 */
class B2;
rand int y;
constraint c { soft y > 10 ; }
endclass  /* c1 */
EXAMPLE:,
class D2 extends B2;
constraint d { soft y inside {[5:9]} ; }
constraint e ;              /* d1 */
rand D1 p1;//rand class constraints
rand B1 p2; ;//rand class constraints
rand D1 p3; ;//rand class constraints
constraint f { soft p1.x < p2.x ; }
Endclass      /* f1 */

constraint D2::e { soft y > 100 ; }
      /* e1 */
D2 d = new();
initial begin
d.randomize() with { soft y inside {10,20,30} ; soft y < p1.x ; };
end  /* i1 */  /* i2 */
PRIORITY:
 The relative priority of the soft constraints (highest 
to lowest) in the above example is:
 i2 ­>i1 ­> f1 ­> e1 ­> d1 ­> c1 ­> p3.b1 ­> p3.a2 ­> 
p3.a1 ­> p2.a2­>p2.a1­>p1.b1­>p1.a2 ­> p1.a1
 If handles p1 and p3 refer to the same object, the 
relative priority is:
 i2 ­> i1 ­> f1 ­> e1 ­> d1 ­> c1 ­> p3.b1 ­> p3.a2 ­> 
p3.a1 ­> p2.a2 ­> p2.a1
CONSTRAINT SOLVER MODEL:
 Soft constraints can only be specified on random 
variables; they may not be specified for randc 
variables.
 Consider two soft constraints c1 and c2, such that c1 
has higher priority than c2.//c1 is the latest.
 1) The constraint solver will first try to produce a 
solution satisfying both c1 and c2.
 2) If it fails in (1) then it will try to produce a solution 
satisfying only c1.
 3) If it fails in (2) then it will try to produce a solution 
satisfying only c2.
 4) If it fails in (3) then it will discard both c1 and c2.
DISABLING SOFT CONSTRAINTS:
 A disable soft constraint on a random variable specifies that 
all lower priority soft constraints that reference the given 
random variable shall be discarded.

class A;
rand int x;
constraint A1 { soft x == 3; }
constraint A2 { disable soft x; } //discard soft constraints
constraint A3 { soft x inside { 1, 2 }; }
Endclass

initial begin
A a = new();
a.randomize();
end
EXAMPLE:
class B;
rand int x;
constraint B1 { soft x == 5; }
constraint B3 {disable soft x//all the lowest priority 
constraints (.i.e soft x==5 ) will be disabled
                                      ; soft x dist {5, 8}; }
endclass
initial begin
B b = new();
b.randomize();
end

Вам также может понравиться