[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] patch for ranvar.{cc,h}



  I'd like to suggest a patch to ranvar.{cc,h}.  When creating
RandomVariables from Tcl, it would be convenient to specify the parameters
when creating the object (as you can when calling the constructor from C).

  For example,

	set myRanVar [new RandomVariable/Pareto 10 1.2]

  instead of

	set myRanVar [new RandomVariable/Pareto]
	$myRanVar set avg_ 10
	$myRanVar set shape_ 1.2

  (though, this form can still be used).

  The patch to implement this change for all of the current
RandomVariables (except Empirical) as of ns-2.1b8 is attached to this
message.

Michele
--
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Michele C. Weigle
[email protected], [email protected]
http://www.cs.unc.edu/~clark

CB# 3175, Sitterson Hall
Department of Computer Science
University of North Carolina
Chapel Hill, NC 27599-3175
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Index: ranvar.cc
===================================================================
RCS file: /net/buzzard/dirt/clark/cvs/ns/ranvar.cc,v
retrieving revision 1.1
retrieving revision 1.3
diff -c -r1.1 -r1.3
*** ranvar.cc	2001/07/03 17:27:35	1.1
--- ranvar.cc	2001/08/16 18:15:53	1.3
***************
*** 74,81 ****
  static class UniformRandomVariableClass : public TclClass {
  public:
  	UniformRandomVariableClass() : TclClass("RandomVariable/Uniform"){}
! 	TclObject* create(int, const char*const*) {
! 		 return(new UniformRandomVariable());
  	 }
  } class_uniformranvar;
  
--- 74,87 ----
  static class UniformRandomVariableClass : public TclClass {
  public:
  	UniformRandomVariableClass() : TclClass("RandomVariable/Uniform"){}
! 	TclObject* create(int argc, const char*const* argv) {
! 		if (argc >= 6) {
! 			return(new UniformRandomVariable ((double) atof(argv[4]), 
! 							  (double) atof(argv[5])));
! 		}
! 		else {
! 			return(new UniformRandomVariable());
! 		}
  	 }
  } class_uniformranvar;
  
***************
*** 100,107 ****
  static class ExponentialRandomVariableClass : public TclClass {
  public:
  	ExponentialRandomVariableClass() : TclClass("RandomVariable/Exponential") {}
! 	TclObject* create(int, const char*const*) {
! 		return(new ExponentialRandomVariable());
  	}
  } class_exponentialranvar;
  
--- 106,119 ----
  static class ExponentialRandomVariableClass : public TclClass {
  public:
  	ExponentialRandomVariableClass() : TclClass("RandomVariable/Exponential") {}
! 	TclObject* create(int argc, const char*const* argv) {
! 		if (argc >= 5) {
! 			return(new ExponentialRandomVariable ((double) 
! 							      atof(argv[4])));
! 		}
! 		else {
! 			return(new ExponentialRandomVariable());
! 		}
  	}
  } class_exponentialranvar;
  
***************
*** 124,131 ****
  static class ParetoRandomVariableClass : public TclClass {
   public:
  	ParetoRandomVariableClass() : TclClass("RandomVariable/Pareto") {}
! 	TclObject* create(int, const char*const*) {
! 		return(new ParetoRandomVariable());
  	}
  } class_paretoranvar;
  
--- 136,149 ----
  static class ParetoRandomVariableClass : public TclClass {
   public:
  	ParetoRandomVariableClass() : TclClass("RandomVariable/Pareto") {}
! 	TclObject* create(int argc, const char*const* argv) {
! 		if (argc >= 6) {
! 			return(new ParetoRandomVariable ((double) atof(argv[4]), 
! 							 (double) atof(argv[5])));
! 		}
! 		else {
! 			return(new ParetoRandomVariable());
! 		}
  	}
  } class_paretoranvar;
  
***************
*** 157,164 ****
  static class ParetoIIRandomVariableClass : public TclClass {
   public:
          ParetoIIRandomVariableClass() : TclClass("RandomVariable/ParetoII") {}
!         TclObject* create(int, const char*const*) {
!                 return(new ParetoIIRandomVariable());
          }
  } class_paretoIIranvar;
  
--- 175,188 ----
  static class ParetoIIRandomVariableClass : public TclClass {
   public:
          ParetoIIRandomVariableClass() : TclClass("RandomVariable/ParetoII") {}
!         TclObject* create(int argc, const char*const* argv) {
! 		if (argc >= 6) {
! 			return(new ParetoIIRandomVariable ((double) atof(argv[4]),
! 							   (double) atof(argv[5])));
! 		}
! 		else {
! 			return(new ParetoIIRandomVariable());
! 		}
          }
  } class_paretoIIranvar;
  
***************
*** 182,189 ****
  static class NormalRandomVariableClass : public TclClass {
   public:
          NormalRandomVariableClass() : TclClass("RandomVariable/Normal") {}
!         TclObject* create(int, const char*const*) {
!                 return(new NormalRandomVariable());
          }
  } class_normalranvar;
   
--- 206,219 ----
  static class NormalRandomVariableClass : public TclClass {
   public:
          NormalRandomVariableClass() : TclClass("RandomVariable/Normal") {}
!         TclObject* create(int argc, const char*const* argv) {
! 		if (argc >= 6) {
! 			return(new NormalRandomVariable ((double) atof(argv[4]),
! 							 (double) atof(argv[5])));
! 		}
! 		else {
! 			return(new NormalRandomVariable());
! 		}
          }
  } class_normalranvar;
   
***************
*** 193,198 ****
--- 223,234 ----
          bind("std_", &std_);
  }
   
+ NormalRandomVariable::NormalRandomVariable(double avg, double std)
+ {
+         avg_ = avg;
+         std_ = std;
+ }
+ 
  double NormalRandomVariable::value()
  {
          return(rng_->normal(avg_, std_));
***************
*** 201,208 ****
  static class LogNormalRandomVariableClass : public TclClass {
   public:
          LogNormalRandomVariableClass() : TclClass("RandomVariable/LogNormal") {}
!         TclObject* create(int, const char*const*) {
!                 return(new LogNormalRandomVariable());
          }
  } class_lognormalranvar;
   
--- 237,252 ----
  static class LogNormalRandomVariableClass : public TclClass {
   public:
          LogNormalRandomVariableClass() : TclClass("RandomVariable/LogNormal") {}
!         TclObject* create(int argc, const char*const* argv) {
! 		if (argc >= 6) {
! 			return(new LogNormalRandomVariable ((double) 
! 							    atof(argv[4]),
! 							    (double) 
! 							    atof(argv[5])));
! 		}
! 		else {
! 			return(new LogNormalRandomVariable());
! 		}
          }
  } class_lognormalranvar;
   
***************
*** 212,217 ****
--- 256,267 ----
          bind("std_", &std_);
  }
   
+ LogNormalRandomVariable::LogNormalRandomVariable(double avg, double std)
+ {
+         avg_ = avg;
+         std_ = std;
+ }
+ 
  double LogNormalRandomVariable::value()
  {
          return(rng_->lognormal(avg_, std_));
***************
*** 220,227 ****
  static class ConstantRandomVariableClass : public TclClass {
   public:
  	ConstantRandomVariableClass() : TclClass("RandomVariable/Constant"){}
! 	TclObject* create(int, const char*const*) {
! 		return(new ConstantRandomVariable());
  	}
  } class_constantranvar;
  
--- 270,283 ----
  static class ConstantRandomVariableClass : public TclClass {
   public:
  	ConstantRandomVariableClass() : TclClass("RandomVariable/Constant"){}
! 	TclObject* create(int argc, const char*const* argv) {
! 		if (argc >= 5) {
! 			return(new ConstantRandomVariable ((double) 
! 							   atof (argv[4])));
! 		}
! 		else {
! 			return(new ConstantRandomVariable());
! 		}
  	}
  } class_constantranvar;
  
***************
*** 249,256 ****
  public:
  	HyperExponentialRandomVariableClass() : 
  	TclClass("RandomVariable/HyperExponential") {}
! 	TclObject* create(int, const char*const*) {
! 		return(new HyperExponentialRandomVariable());
  	}
  } class_hyperexponentialranvar;
  
--- 305,320 ----
  public:
  	HyperExponentialRandomVariableClass() : 
  	TclClass("RandomVariable/HyperExponential") {}
! 	TclObject* create(int argc, const char*const* argv) {
! 		if (argc >= 6) {
! 			return(new HyperExponentialRandomVariable ((double) 
! 							    atof(argv[4]),
! 							    (double) 
! 							    atof(argv[5])));
! 		}
! 		else {
! 			return(new HyperExponentialRandomVariable());
! 		}
  	}
  } class_hyperexponentialranvar;
  
Index: ranvar.h
===================================================================
RCS file: /net/buzzard/dirt/clark/cvs/ns/ranvar.h,v
retrieving revision 1.1
retrieving revision 1.3
diff -c -r1.1 -r1.3
*** ranvar.h	2001/07/03 17:27:35	1.1
--- ranvar.h	2001/08/16 18:15:54	1.3
***************
*** 106,111 ****
--- 107,113 ----
   public:
          virtual double value();
          NormalRandomVariable();
+ 	NormalRandomVariable(double, double);
          inline double* avgp() { return &avg_; };
          inline double* stdp() { return &std_; };
          inline double avg()     { return avg_; };
***************
*** 121,126 ****
--- 123,129 ----
  public:
          virtual double value();
          LogNormalRandomVariable();
+ 	LogNormalRandomVariable(double, double);
          inline double* avgp() { return &avg_; };
          inline double* stdp() { return &std_; };
          inline double avg()     { return avg_; };