📄 item.cpp
字号:
// item.cpp: implementation of the item class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "travelSP.h"
#include "item.h"
#include "stdlib.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
item::item()
{
}
item::~item()
{
}
void item::setbit(unsigned long *num,int bit,int value)
{
unsigned long mask;
if(value!=0)mask=1;
else mask=0;
if(mask==1)
{
mask=mask<<bit;
*num=*num|mask;
}
else
{
mask=1;
mask=mask<<bit;
mask=~mask;
*num=*num&mask;
}
}
int item::getbit(unsigned long *num,int bit)//get the value of bit.
{
unsigned long mask;
int p;
mask=1;
mask=mask<<bit;
p=*num&mask;
if(p!=0)return 1;
else return 0;
}
int item::flip(double rate)//返回值为1的概率为rate.
{
int i;
double n,f;
i=rand();
n=(double)i/32767.0;
f=n+rate;
if(f>1)
return 1;
else
return 0;
}
double item::random() //0-1 random number
{
return (double)rand()/32767.0;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -