Signal Interference -(hdu5130)

本文介绍了一种计算在两个国家A国和B国之间的战争中,B国建造的无线电塔对A国无线电塔信号干扰的有效覆盖面积的方法。通过输入A国领土的多边形顶点坐标和特定参数k,利用几何算法确定被干扰区域与A国领土相交的面积。
Two countries A-Land and B-Land are at war. The territory of A-Land is a simple polygon with no more than 500 vertices. For military use, A-Land constructed a radio tower (also written as A), and it's so powerful that the whole country was under its signal. To interfere A-Land's communication, B-Land decided to build another radio tower (also written as B). According to an accurate estimation, for any point P, if the euclidean distance between P and B is no more than k (0.2 ≤ k < 0.8) times of the distance between P and A, then point P is not able to receive clear signals from A, i.e. be interfered. Your task is to calculate the area in A-Land's territory that are under B-Land's interference.
Input
There are no more than 100 test cases in the input. 

In each test case, firstly you are given a positive integer N indicating the amount of vertices on A-Land's territory, and an above mentioned real number k, which is rounded to 4 digits after the decimal point. 

Then N lines follow. Each line contains two integers x and y (|x|, |y| ≤ 1000), indicating a vertex's coordinate on A's territory, in counterclockwise or clockwise order. 

The last two lines of a test case give radio tower A and B's coordinates in the same form as vertexes' coordinates. You can assume that A is not equal to B.
Output
For each test case, firstly output the case number, then output your answer in one line following the format shown in sample. Please note that there is a blank after the ':'. 

Your solution will be accepted if its absolute error or relative error is no more than 10-6. 

This problem is special judged.
Sample Input
4 0.5000
-1 -1
1 -1
1 1
-1 1
0 0
-1 0
Sample Output

Case 1: 0.2729710441




题意: 求所有满足PB <= k*PA 的P所在区域与多边形的交面积。

解题思路就是求出圆和多边形相交的面积,这里求出圆的方程就好了,套用模板;



这个是求出的圆的方程

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

const double eps=1e-8;
const double PI=acos(-1);
const int maxn=1005;
struct point
{
    double x,y;
    point() {}
    point (double xx,double yy):x(xx),y(yy) {}
    friend point operator-(const point &a,const point &b)
    {
        return point (a.x-b.x,a.y-b.y);
    }
    friend point operator *(const point &a,const double &b)
    {
        return point(a.x*b,a.y*b);
    }
    friend point operator /(const point &a,const double &b)
    {
        return point (a.x/b,a.y/b);
    }
} A,B,res[maxn];
double k,r;
int n;
double sqr(double x)
{
    return x*x;
}
int dcmp(double k)
{
    return k<-eps?-1:k>eps?1:0;
}
double dot(const point &a,const point &b)
{
    return a.x*b.x+a.y*b.y;
}
double cross(const point &a,const point &b)
{
    return a.x*b.y-a.y*b.x;
}
double abs(const point o)
{
    return sqrt(dot(o,o));
}
point crosspt(const point &a,const point &b,const point &p,const point &q)
{
    double a1=cross(b-a,p-a);
    double a2=cross(b-a,q-a);
    return (p*a2-q*a1)/(a2-a1);
}
double mysqrt(double n)
{
    return sqrt(max(0.0,n));
}
double sector_area(const point &a,const point &b)
{
    double theta=atan2(a.y,a.x)-atan2(b.y,b.x);
    while(theta<=0) theta+=2*PI;
    while(theta>2*PI) theta-=2*PI;
    theta=min(theta,2*PI-theta);
    return r*r*theta/2;
}
void circle_cross_line(const point &a,const point &b,const point &o,double r,point ret[],int &num)
{
    double x0=o.x,y0=o.y;
    double x1=a.x,y1=a.y;
    double x2=b.x,y2=b.y;
    double dx=x2-x1,dy=y2-y1;
    double A=dx*dx+dy*dy;
    double B=2*dx*(x1-x0)+2*dy*(y1-y0);
    double C=sqr(x1-x0)+sqr(y1-y0)-sqr(r);
    double delta=B*B-4*A*C;
    num=0;
    if(dcmp(delta)>=0)
    {
        double t1=(-B-mysqrt(delta))/2/A;
        double t2=(-B+mysqrt(delta))/2/A;
        if(dcmp(t1-1)<=0&&dcmp(t1)>=0)
            ret[num++]=point(x1+t1*dx,y1+t1*dy);
        if(dcmp(t2-1)<=0&&dcmp(t2)>=0)
            ret[num++]=point(x1+t2*dx,y1+t2*dy);
    }
}
double calc(const point &a,const point &b)
{
    point p[2];
    int num=0;
    int ina=dcmp(abs(a)-r)<0;
    int inb=dcmp(abs(b)-r)<0;
    if (ina&&inb)
        return fabs(cross(a,b)/2.0);
    circle_cross_line(a,b,point(0,0),r,p,num);
    if(ina)
        return sector_area(b,p[0])+fabs(cross(a,p[0]))/2.0;
    if(inb)
        return sector_area(p[0],a)+fabs(cross(p[0],b))/2.0;
    if(num==2)
        return sector_area(a,p[0])+sector_area(p[1],b)+fabs(cross(p[0],p[1]))/2.0;
    return sector_area(a,b);
}
double area()
{
    double ret=0;
    for(int i=0; i<n; i++)
    {
        int sgn=dcmp(cross(res[i],res[i+1]));
        if(sgn!=0)  ret+=sgn*calc(res[i],res[i+1]);
    }
    return ret;
}
void init(point ret[],int n,double xx,double yy)
{
    for(int i=0; i<n; i++)
    {
        ret[i].x-=xx;
        ret[i].y-=yy;
    }
    ret[n]=ret[0];
}
int main()
{
    int cas=0;
    while(~scanf("%d",&n))
    {
        cas++;
        scanf("%lf",&k);
        for(int i=0; i<n; i++)
            scanf("%lf%lf",&res[i].x,&res[i].y);
        scanf("%lf%lf",&A.x,&A.y);
        scanf("%lf%lf",&B.x,&B.y);
        double E=(2*B.x-2*sqr(k)*A.x)/(1.0-sqr(k));
        double F=(2*B.y-2*sqr(k)*A.y)/(1.0-sqr(k));
        double G=(sqr(k*A.x)+sqr(k*A.y)-sqr(B.x)-sqr(B.y))/(1.0-sqr(k));
        double x0=E/2.0,y0=F/2.0;
        r=sqrt(G+sqr(E)/4.0+sqr(F)/4.0);
        for(int i=0; i<n; i++)
        {
            res[i].x-=x0;
            res[i].y-=y0;
        }
        res[n]=res[0];
        printf("Case %d: %.10lf\n",cas,fabs(area()));
    }
    return 0;
}









### 三、最大化主传输SINR并保证标签SINR约束的收发器设计随机优化方法 在无线通信系统中,收发器设计的目标通常包括最大化主链路的信噪比(SINR),同时确保所有次级链路(如标签)满足一定的SINR要求。这一问题可以建模为一个带约束的优化问题,其中目标函数是主链路的SINR,约束条件是各个标签的最小SINR阈值。由于无线信道具有时变特性,采用随机优化方法可以更有效地适应动态环境。 在随机优化框架下,系统参数(如信道状态信息、噪声功率)被视为随机变量,优化过程通过引入随机梯度下降(SGD)或其变种(如Adam)来调整发射机和接收机的参数,使得目标函数在期望意义下最优,同时满足概率意义上的SINR约束[^1]。Adam优化器因其对非平稳目标的良好适应性,常用于在线优化任务,尤其适合无线通信系统中动态变化的信道环境[^2]。 一个典型的随机优化问题可以表示为: $$ \max_{\mathbf{w}, \mathbf{v}} \mathbb{E} \left[ \frac{|\mathbf{v}^H \mathbf{H} \mathbf{w}|^2}{\sigma^2 + \sum_{i} |\mathbf{v}^H \mathbf{G}_i \mathbf{w}_i|^2} \right] $$ $$ \text{subject to } \mathbb{E} \left[ \frac{|\mathbf{v}_i^H \mathbf{G}_i \mathbf{w}|^2}{\sigma^2 + \sum_{j \neq i} |\mathbf{v}_i^H \mathbf{G}_i \mathbf{w}_j|^2} \right] \geq \gamma_i, \quad \forall i $$ 其中,$\mathbf{w}$ 和 $\mathbf{v}$ 分别表示发射波束成形向量和接收滤波向量,$\mathbf{H}$ 是主链路的信道矩阵,$\mathbf{G}_i$ 是第 $i$ 个标签的信道矩阵,$\sigma^2$ 是噪声功率,$\gamma_i$ 是第 $i$ 个标签的SINR阈值。目标函数和约束条件中的期望反映了信道状态的随机性。 在实际实现中,可以通过采样多个信道状态并计算梯度的平均值来近似期望,进而使用Adam算法进行参数更新。Adam的更新规则可以表示为: $$ m_t = \beta_1 m_{t-1} + (1 - \beta_1) g_t \\ v_t = \beta_2 v_{t-1} + (1 - \beta_2) g_t^2 \\ \hat{m}_t = \frac{m_t}{1 - \beta_1^t} \\ \hat{v}_t = \frac{v_t}{1 - \beta_2^t} \\ \theta_t = \theta_{t-1} - \alpha \frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \epsilon} $$ 其中,$\theta$ 是待优化参数,$g_t$ 是第 $t$ 步的梯度,$\alpha$ 是学习率,$\beta_1$ 和 $\beta_2$ 是动量参数,$\epsilon$ 是一个小常数以防止除零错误。Adam算法通过动量项和自适应学习率调整,使得优化过程在高维空间中更加稳定和高效[^2]。 以下是一个基于Adam优化器的Python示例,用于最大化主链路SINR并满足标签SINR约束: ```python import numpy as np import torch from torch.optim import Adam # 模拟信道状态 def generate_channels(num_tags, num_antennas): H = np.random.randn(num_antennas) + 1j * np.random.randn(num_antennas) G = [np.random.randn(num_antennas) + 1j * np.random.randn(num_antennas) for _ in range(num_tags)] return H, G # 计算主链路SINR def compute_primary_sinr(w, H, G, noise_power): signal = np.abs(np.vdot(H, w))**2 interference = sum(np.abs(np.vdot(g, w))**2 for g in G) return signal / (noise_power + interference) # 计算标签i的SINR def compute_tag_sinr(w, G_i, G_rest, noise_power): signal = np.abs(np.vdot(G_i, w))**2 interference = sum(np.abs(np.vdot(g, w))**2 for g in G_rest) return signal / (noise_power + interference) # 设置参数 num_tags = 3 num_antennas = 4 noise_power = 0.1 gamma = [2.0 for _ in range(num_tags)] # 标签SINR阈值 # 初始化波束成形向量 w = torch.randn(num_antennas, requires_grad=True) optimizer = Adam([w], lr=0.01) # 优化循环 for step in range(1000): H, G = generate_channels(num_tags, num_antennas) H_tensor = torch.tensor(H, dtype=torch.complex64) G_tensor = [torch.tensor(g, dtype=torch.complex64) for g in G] # 主链路SINR signal = torch.abs(torch.vdot(H_tensor, w))**2 interference = sum(torch.abs(torch.vdot(g, w))**2 for g in G_tensor) primary_sinr = signal / (noise_power + interference) # 标签SINR约束 tag_sinrs = [] for i in range(num_tags): signal_i = torch.abs(torch.vdot(G_tensor[i], w))**2 interference_i = sum(torch.abs(torch.vdot(G_tensor[j], w))**2 for j in range(num_tags) if j != i) tag_sinr = signal_i / (noise_power + interference_i) tag_sinrs.append(tag_sinr) # 构造目标函数(最大化主链路SINR,同时满足标签SINR约束) constraint_violation = sum(torch.relu(gamma[i] - tag_sinrs[i]) for i in range(num_tags)) loss = -primary_sinr + 10 * constraint_violation # 用惩罚项处理约束 optimizer.zero_grad() loss.backward() optimizer.step() if step % 100 == 0: print(f"Step {step}: Primary SINR = {primary_sinr.item()}, Loss = {loss.item()}") ``` 该示例展示了如何使用Adam优化器进行波束成形设计,以最大化主链路SINR,同时确保所有标签的SINR不低于设定阈值。通过引入惩罚项,可以将SINR约束转化为可微分的目标函数,从而利用Adam进行优化。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值