GitHub中Asterank源码python修改成C++(本人python不太会)

GitHub - typpo/asterank: asteroid database, interactive visualizations, and discovery tools

主要目的是在进行多元线性回归的时候将枚举型转换为数值型

python:

#
# The constants used in calculations for the values of asteroids.
#

# General constants
GENERAL_INDEX = {
  'cost_to_orbit': 2200,  # $ / kg
}

# Keys are asteroid spectra type. Values are maps from a material
# to the percent mass of each material.
SPECTRA_INDEX = {
  '?': {},
  'A': {},
  'B': {
    'hydrogen': 0.235,
    'nitrogen': 0.001,
    'ammonia': 0.001,
    'iron': 10,
  },
  'C': {
    # from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf
    'water': .2,
    'iron': .166,
    'nickel': .014,
    'cobalt': .002,

    # volatiles
    'hydrogen': 0.235,
    'nitrogen': 0.001,
    'ammonia': 0.001,
  },
  'Ch': {
    # from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf
    'water': .2,
    'iron': .166,
    'nickel': .014,
    'cobalt': .002,

    # volatiles
    'hydrogen': 0.235,
    'nitrogen': 0.001,
    'ammonia': 0.001,
  },
  'Cg': {
    # from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf
    'water': .2,
    'iron': .166,
    'nickel': .014,
    'cobalt': .002,

    # volatiles
    'hydrogen': 0.235,
    'nitrogen': 0.001,
    'ammonia': 0.001,
  },
  'Cgh': {
    # from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf
    'water': .2,
    'iron': .166,
    'nickel': .014,
    'cobalt': .002,

    # volatiles
    'hydrogen': 0.235,
    'nitrogen': 0.001,
    'ammonia': 0.001,
  },
  'C type': {
    # from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf
    'water': .2,
    'iron': .166,
    'nickel': .014,
    'cobalt': .002,

    # volatiles
    'hydrogen': 0.235,
    'nitrogen': 0.001,
    'ammonia': 0.001,
  },
  'Cb': {   # transition object between C and B
    # from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf
    'water': .1,
    'iron': .083,
    'nickel': .007,
    'cobalt': .001,

    # volatiles
    'hydrogen': 0.235,
    'nitrogen': 0.001,
    'ammonia': 0.001,
  },
  'D': {
    'water': 0.000023,
  },
  'E': {

  },
  'K': {  # cross between S and C
    # from Keck report at http://www.kiss.caltech.edu/study/asteroid/asteroid_final_report.pdf
    'water': .1,
    'iron': .083,
    'nickel': .007,
    'cobalt': .001,

    # volatiles
    'hydrogen': 0.235,
    'nitrogen': 0.001,
    'ammonia': 0.001,
  },
  'L': {
    'magnesium silicate': 1e-30,
    'iron silicate': 0,
    'aluminum': 7
  },
  'Ld': {  # copied from S
    'magnesium silicate': 1e-30,
    'iron silicate': 0,
  },
  'M': {
    'iron': 88,
    'nickel': 10,
    'cobalt': 0.5,
  },
  'O': {
    'nickel-iron': 2.965,
    'platinum': 1.25,
  },
  'P': {  # correspond to CI, CM carbonaceous chondrites
    'water': 12.5,
  },
  'R': {
    'magnesium silicate': 1e-30,
    'iron silicate': 0,
  },
  'S': {
    'magnesium silicate': 1e-30,
    'iron silicate': 0,
  },
  # Sa, Sq, Sr, Sk, and Sl all transition objects (assume half/half)
  'Sa': {
    'magnesium silicate': 5e-31,
    'iron silicate': 0,
  },
  'Sq': {
    'magnesium silicate': 1e-30,
    'iron silicate': 0,
  },
  'Sr': {
    'magnesium silicate': 1e-30,
    'iron silicate': 0,
  },
  'Sk': {
    'magnesium silicate': 1e-30,
    'iron silicate': 0,
  },
  'Sl': {
    'magnesium silicate': 1e-30,
    'iron silicate': 0,
  },
  'S(IV)': {
    'magnesium silicate': 1e-30,
    'iron silicate': 0,
  },
  'Q': {
    'nickel-iron': 13.315,
  },
  'R': {
    'magnesium silicate': 1e-30,
    'iron silicate': 0,
  },
  'T': {
    'iron': 6,
  },
  'U': {

  },
  'V': {
    'magnesium silicate': 1e-30,
    'iron silicate': 0,
  },

  # TODO use density to decide what kind of X the object is?

  'X': {  # TODO these vals only apply to M-type within X
    'iron': 88,
    'nickel': 10,
    'cobalt': 0.5,
  },
  'Xe': {  # TODO these vals only apply to M-type within X
    'iron': 88,
    'nickel': 10,
    'cobalt': 0.5,
  },
  'Xc': {  # TODO these vals only apply to M-type within X
    'iron': 88,
    'nickel': 10,
    'cobalt': 0.5,
    'platinum': 0.005,
  },
  'Xk': {  # TODO these vals only apply to M-type within X
    'iron': 88,
    'nickel': 10,
    'cobalt': 0.5,
  },
  'comet': {
      # no estimates for now, because assumed mass, etc. would be off
  },
}


# Keys are raw materials. Values are maps containing information on
# the value of these materials.
MATERIALS_INDEX = {
  'water': {
    '$_per_kg': 0.01
  },
  'hydrogen': {
    '$_per_kg': 3.65808137,
  },
  'nitrogen': {
    '$_per_kg': 0.074094,
  },
  'ammonia': {
    '$_per_kg': 0.01,
  },
  'oxygen': {
    '$_per_kg': 0.21,
  },
  'iron': {
    '$_per_kg': 2e-7,
  },
  'nickel': {
    '$_per_kg': 0.00002,
  },
  'nickel-iron': {  # value unclear.  averaged.
    '$_per_kg': 1.01e-5,
  },
  'cobalt': {
    '$_per_kg': 0.20,
  },
  'stainless steel': {
    '$_per_kg': 0.20
  },
  'platinum': {
    '$_per_kg': 2
  },
  'magnesium silicate': {
    '$_per_kg': 1e-25,
  },
  'iron silicate': {
    '$_per_kg': 0,
  },
  'aluminum': {
    '$_per_kg': 0.05
  }
}

def valuePerKg(type):
  mat_price_per_kg = 0
  for mat, pct in SPECTRA_INDEX[type].iteritems():
    mat_price_per_kg += MATERIALS_INDEX[mat]['$_per_kg'] * pct / 100
  return mat_price_per_kg

def savedPerKg(type):
  # This is is a dummy calculation used to compare the cost of mining in space
  # to the cost of getting the same materials from earth.
  cto = GENERAL_INDEX['cost_to_orbit']
  ret = 0
  for mat,pct in SPECTRA_INDEX[type].iteritems():
    ret += cto * pct / 100
  return ret - (cto / 3)  # assume it costs 1/3 as much to mine and get off the asteroid

def profitRatio(baseline_dv, dv):
  # Baseline profit is 10%, but it changes based on dv
  return baseline_dv / dv

C++代码:

#include <iostream>
#include <string>
//函数Price_p返回元素的单位价格
float Price_p(std::string str){
     float per_kg=0;
     if(str=="water")
          per_kg=0.01;
     if (str == "hydrogen")
          per_kg = 3.65808137;
     if (str == "nitrogen")
          per_kg = 0.074094;
     if (str == "ammonia")
          per_kg = 0.01;
     if (str == "oxygen")
          per_kg = 0.21;
     if (str == "iron")
          per_kg = 2e-7;
     if (str == "nickel")
          per_kg = 0.00002;
     if (str == "nickel-iron")
          per_kg = 1.01e-5;
     if (str == "ncobalt")
          per_kg = 0.2;
     if (str == "stainless steel")
          per_kg = 0.2;
     if (str == "platinum")
          per_kg = 2;
     if (str == "magnesium silicate")
          per_kg = 1e-25;
     if (str == "iron silicate")
          per_kg = 0;
     if (str == "aluminum")
          per_kg = 0.05;

     return per_kg;
}

float how_Much(std::string str_00){
if(str_00=="B"){
   return Price_p("hydrogen")*0.235+Price_p("nitrogen")*0.001+Price_p("ammonia")*0.001+Price_p("iron")*10;
    }
if (str_00 == "C"){
   return Price_p("water") * 0.2 + Price_p("iron") * 0.166 + Price_p("nickel") * 0.014 + Price_p("cobalt") * 0.002+Price_p("hydrogen") * 0.235
       + Price_p("nitrogen") * 0.001+Price_p("ammonia") * 0.001+Price_p("ammonia") *0.001;
    }
if (str_00== "Ch"){
   return Price_p("water") * 0.2 + Price_p("iron") * 0.166 + Price_p("nickel") * 0.014 + Price_p("cobalt") * 0.002+Price_p("hydrogen") * 0.235
       + Price_p("nitrogen") * 0.001+Price_p("ammonia") * 0.001;
    }
if (str_00== "Cg"){
   return Price_p("water") * 0.2 + Price_p("iron") * 0.166 + Price_p("nickel") * 0.014 + Price_p("cobalt") * 0.002+Price_p("hydrogen") * 0.235
       + Price_p("nitrogen") * 0.001+Price_p("ammonia") * 0.001;
    }
if (str_00== "Cgh"){
   return Price_p("water") * 0.2 + Price_p("iron") * 0.166 + Price_p("nickel") * 0.014 + Price_p("cobalt") * 0.002+Price_p("hydrogen") * 0.235
       + Price_p("nitrogen") * 0.001+Price_p("ammonia") * 0.001;
    }
if (str_00== "C type"){
   return Price_p("water") * 0.2 + Price_p("iron") * 0.166 + Price_p("nickel") * 0.014 + Price_p("cobalt") * 0.002+Price_p("hydrogen") * 0.235
       + Price_p("nitrogen") * 0.001+Price_p("ammonia") * 0.001;
    }
if (str_00 == "Cb"){
     return Price_p("water") * 0.1 + Price_p("iron") * 0.083 + Price_p("nickel") * 0.007 +
             Price_p("cobalt") * 0.001 + Price_p("hydrogen") * 0.235+ Price_p("nitrogen") * 0.001 + Price_p("ammonia") * 0.001;
}
if (str_00 == "D"){
     return Price_p("water") * 0.000023 ;}

if (str_00 == "E"){
return 0;}

if (str_00 == "K"){
     return Price_p("water") * 0.1 + Price_p("iron") * 0.083 + Price_p("nickel") * 0.007 +
             Price_p("cobalt") * 0.001 + Price_p("hydrogen") * 0.235+ Price_p("nitrogen") * 0.001 + Price_p("ammonia") * 0.001;
}
if (str_00 == "L"){
     return Price_p("magnesium silicate") * 1e-30 + Price_p("iron silicate") * 0 + Price_p("aluminum") * 7 ;
}
if (str_00 == "Ld"){
     return Price_p("magnesium silicate") * 1e-30 + Price_p("iron silicate") * 0 ;
}
if (str_00 == "M"){
     return Price_p("iron") * 88 + Price_p("nickel") * 10 + Price_p("cobalt") * 0.5;
}
if (str_00 == "O"){
     return Price_p("nickel-iron") * 2.965 + Price_p("platinum") * 1.25;
}
if (str_00 == "P"){
     return Price_p("water") * 12.5;
}
if (str_00 == "R"){
     return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "S"){
     return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "Sa"){
     return Price_p("magnesium silicate") * 5e-31+Price_p("iron silicate") * 0;
}

if (str_00 == "Sq"){
     return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "Sr"){
     return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "Sk"){
     return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "Sl"){
return Price_p("magnesium silicate") * 1e-30 + Price_p("iron silicate") * 0;
}
if (str_00 == "S(IV)"){
     return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "Q"){
     return Price_p("nickel-iron") * 13.315;
}
if (str_00 == "R"){
     return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "T"){
     return Price_p("iron") * 6;
}
if (str_00 == "U"){
     return 0;
}
if (str_00 == "V"){
     return Price_p("magnesium silicate") * 1e-30+Price_p("iron silicate") * 0;
}
if (str_00 == "X"){
     return Price_p("iron") * 88+Price_p("nickel") * 10+Price_p("cobalt") * 0.5;
}
if (str_00 == "Xe"){
     return Price_p("iron") * 88+Price_p("nickel") * 10+Price_p("cobalt") * 0.5;
}
if (str_00 == "Xc"){
     return Price_p("iron") * 88+Price_p("nickel") * 10+Price_p("cobalt") * 0.5+Price_p("platinum") * 0.005;
}
if (str_00 == "Xk"){
     return Price_p("iron") * 88+Price_p("nickel") * 10+Price_p("cobalt") * 0.5;
}

 return 0;
}

int main() {
   std::string str_00="C";
     while(str_00!="00") {
          std::cin>>str_00;
          std::cout<<"The price of Type "+str_00+"is:"<<how_Much(str_00);
     }
    return 0;
}

运行结果:

相当于每千克Q类型的小行星值多少美元 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/607323.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

基于Detectron2的计算机视觉实践

书籍&#xff1a;Hands-On Computer Vision with Detectron2: Develop object detection and segmentation models with a code and visualization approach 作者&#xff1a;Van Vung Pham&#xff0c;Tommy Dang 出版&#xff1a;Packt Publishing 书籍下载-《基于Detectr…

.OpenNJet应用引擎实践——从 0-1 体验感受

目录 一. &#x1f981; 写在前面二. &#x1f981; 安装使用2.1 安装环境2.2 配置yum源2.3 安装软件包2.4 编译代码2.5 启动 三. &#x1f981; 使用效果3.1 编辑配置文件3.2 编辑 HTML 代码 四. &#x1f981; 使用感受 一. &#x1f981; 写在前面 现在互联网体系越来越往云…

小丑的身份证和复印件 (BFS + Floyd)

本题链接&#xff1a;登录—专业IT笔试面试备考平台_牛客网 题目&#xff1a; 样例&#xff1a; 输入 2 10 (JOKERjoke #####asdr) 输出 12 思路&#xff1a; 根据题意&#xff0c;要求最短时间&#xff0c;实际上也可以理解为最短距离。 所以应该联想到有关最短距离的算法&…

css z-Index 详解--子元素盖在父元素的兄弟元素上

前置知识 1、z-index 只有在定位元素上才会生效&#xff08;即非static定位的元素上&#xff09; 2、同级元素&#xff0c;无论是z-index 相同还是没设置。后面的元素层级比前面 3、元素上有 transform 属性 z-index 会失效 dom结构如下 // dom部分 <div><div id&quo…

latex algorithm2e 库学习总结

案例1 \documentclass{article}\usepackage{xeCJK} \usepackage[]{algorithm2e} %\usepackage{ctex} % 中文包\begin{document}\renewcommand{\algorithmcfname}{算法} % 把标题设置为“算法” \begin{algorithm…

html table thead打印时带重复表头不生效

今天做一个打印功能时要求每页都带相同的表头&#xff0c;使用的方式是table的thead标签来实现&#xff0c;结果发现thead里边的内容放多了之后只有第一页才会有表头。最后发现问题是 thead的内容不能超过table的25%。

实例分割——Mask R-CNN、YOLOV8、RTMDET、DeepLab四种实例分割算法比对

1.概述 1.1 语义分割与实例分割 实例分割和语义分割都是计算机视觉领域中图像分割的任务&#xff0c;它们在目标和方法上有一些区别&#xff1a; 语义分割&#xff1a; 语义分割的目标是对图像中的每个像素打上类别标签&#xff0c;即识别出图像中每个像素属于哪个预定义的…

云动态摘要 2024-05-09

给您带来云厂商的最新动态&#xff0c;最新产品资讯和最新优惠更新。 最新优惠与活动 [免费试用]即刻畅享自研SaaS产品 腾讯云 2024-04-25 涵盖办公协同、营销拓客、上云安全保障、数据分析处理等多场景 云服务器ECS试用产品续用 阿里云 2024-04-14 云服务器ECS试用产品续用…

YOLOv5,YOLOv7改进之结合​SOCA

1.SOCA moudle结构图 2,YOLOv5,YOLOv7改进之结合​SOCA 1.配置common.py文件 #SOCA moudle 单幅图像超分辨率 class Covpool(Function):@staticmethoddef forward(ctx, input):x = inputbatchSize = x.data.shape[0]dim = x.data.shape[1]h = x.data.shape[2]w = x.data.sha…

PLC学习笔记

PLC学习笔记 前言一、一些基操知识二、GX works2编程2.1 位逻辑1.2 中间寄存器1.3 PLC的扫描方式 总结 前言 我这个人真的是太渴望知识了~ 一、一些基操知识 一般X表示输入&#xff0c;Y表示输出。一般八个为一组X0~X7M表示中间寄存器&#xff0c;M0~M7时间T、计数C 二、GX …

短信群发公司

伴随着移动互联网和智能手机的普及&#xff0c;短信群发成为了企业与个人之间高效沟通的一种重要方式。短信群发公司应运而生&#xff0c;致力于为用户提供专业、安全、高效的群发服务。 服务内容 短信群发公司提供多样化的服务内容&#xff0c;满足不同用户的需求。短信群发公…

javaWeb快速部署到tomcat阿里云服务器

目录 准备 关闭防火墙 配置阿里云安全组 点击控制台 点击导航栏按钮 点击云服务器ECS 点击安全组 点击管理规则 点击手动添加 设置完成 配置web服务 使用yum安装heepd服务 启动httpd服务 查看信息 部署java通过Maven打包好的war包项目 Maven打包项目 上传项目 …

深度学习笔记001

目录 一、批量规范化 二、残差网络ResNet 三、稠密连接网络&#xff08;DenseNet&#xff09; 四、循环神经网络 五、信息论 六、梯度截断 本篇blog仅仅是本人在学习《动手学深度学习 Pytorch版》一书中做的一些笔记&#xff0c;感兴趣的读者可以去官网http://zh.gluon.a…

Abp框架,EF 生成迁移文件时,自动添加表和字段注释内容

在使用 abp 框架&#xff0c;或者ef 的时候都会遇到一个问题&#xff0c;就是建实体后要将实体描述生成到数据库中&#xff0c;就需要手动去添加 [Comment("注释内容")] 注解&#xff0c;这样相当于手动写两次注释&#xff08;即使你是 Ctrl C&#xff09;&#x…

若依集成mybatis-plus 超详细教程(亲测可用)

文章目录 简介步骤第一步第二步第三步第四步第五步第六步 使用QueryWrapperservice层impl 实现接口类层Mapper层 简介 话不多说 直接跟着下面的教程操作&#xff0c;如果有报错私信我&#xff0c;或者通过博文下面的微信名片加我微信&#xff0c;免费解答哦&#xff01; 步骤 …

解决方案:‘Series‘ object has no attribute ‘xxxx‘

文章目录 一、现象二、解决方案 一、现象 ...... model.fit(X_train, y_train) y_pred model.predict(X_test) recall recall_score(y_test, y_pred) precision precision_score(y_test. y_pred) ......执行语句到**“precision precision_score(y_test. y_pred)”**这里发…

StarRocks 跨集群数据迁移,SDM 帮你一键搞定!

作者&#xff1a;严祥光&#xff0c;StarRocks Active Contributor&#xff0c;StarRocks 存算分离核心研发&#xff0c;在社区中主要负责数据导入、跨集群同步、数据迁移和容灾等工作。 有时候&#xff0c;你可能会为以下需求而苦恼&#xff0c;苦苦搜索更好的解决方案&#x…

记录创建项目java version 没有8的问题

问题&#xff1a; 解决方案 java版本选择21&#xff08;21可以兼容jdk8&#xff09; SpringBoot选择3.2.5 进入项目后手动在pom.xml中修改版本

基于stm32的spi从机实验HAL库编程

目录 基于stm32的spi从机实验HAL库编程前言业务场景硬件设计接线配置swd接口配置spi配置DMA配置中断配置系统时钟配置工程生成代码写点从机代码上机现象后记本文使用的测试工程 基于stm32的spi从机实验HAL库编程 前言 在微控制器的世界中&#xff0c;串行外设接口(SPI)是一种…

java面向对象实现文字格斗游戏细节完善版

为了完善上一篇的文字格斗游戏的细节&#xff0c;所以加了些代码&#xff0c;使得交互更加的具体有趣! 效果 大家可以多运行几次代码&#xff0c;得到不同的战况&#xff01;&#xff01; 代码实现 1.bean类 import java.util.Random;public class TextGame {private Strin…
最新文章