2011|08|
2013|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|05|06|07|08|09|10|11|12|
2016|01|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|

2019-08-07 大統領選挙のシミュレーション GO言語 超高速版 [長年日記]

_ https://mail.google.com/mail/u/0/?tab=rm&ogbl#search/%E5%85%88%E7%A8%8B%E3%81%AE1%E4%B8%87%E4%B8%A6%E8%A1%8C%E3%81%AE%E3%83%A1%E3%83%A2%E3%82%B3%E3%83%BC%E3%83%89%E3%81%AE%E4%BB%B6/CllgCHrlFNhQlzspPFwRwbqClbkjcnBKJhtxZnJpkJhFgZlVlztkbzfzvsqrRScCvsjnPzrcTgV


2019-08-09 シミュレーテッドアニーリングのサンプルプログラム [長年日記]

/*
 gcc 2_simple_sa.c -o 2_simple_sa -lm
*/
 
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
 
 
float distance(int *point1, int *point2)
{
  int
    dx = point1[0] - point2[0],
    dy = point1[1] - point2[1];
 
  return sqrt(dx * dx + dy * dy);
}
 
 
float totalDistance(int **points, int length)
{
  int
    i;
  float
    total = 0.0;
 
  for (i = 1; i < length; i++) {
    total += distance(points[i], points[i - 1]);
  }
 
  total += distance(points[0], points[length - 1]);
 
  return total;
}
 
 
void swap(int **array, int index1, int index2)
{
  int
    *tmp;
 
  tmp = array[index1];
  array[index1] = array[index2];
  array[index2] = tmp;
}
 
 
float frand()
{
  return (float)rand()/(float)RAND_MAX;
}
 
 
int shouldChange(float delta, float t)
{
  if (delta <= 0) return 1;
  if (frand() < exp(- delta / t)) return 1;
  return 0;
}
 
 
void sa(int **route,
        int numberOfCities,
        float initialT,
        float finalT,
        int n,
        float coolingRate)
{
  int
    currentIterations,
    randomIndex1,
    randomIndex2,
    i;
  float
    t,
    currentTotalDistance,
    newTotalDistance;
 
  currentTotalDistance = totalDistance(route, numberOfCities);
 
  for (t = initialT; t > finalT; t *= coolingRate) {
    for (i = 0; i < n; i++) {
      randomIndex1 = rand() % numberOfCities;
      randomIndex2 = rand() % numberOfCities;
 
      swap(route, randomIndex1, randomIndex2);
 
      newTotalDistance = totalDistance(route, numberOfCities);
 
      if (shouldChange(newTotalDistance - currentTotalDistance, t)) {
        currentTotalDistance = newTotalDistance;
      } else {
        swap(route, randomIndex1, randomIndex2);
      }
    }
  }
 
}
 
 
int **buildRoute(int mapData[][2], int numberOfCities)
{
  int
    **route = calloc(numberOfCities, sizeof(&mapData[0][0])),
    i;
 
  for (i = 0; i < numberOfCities; i++) {
    route[i] = mapData[i];
  }
  return route;
}
 
 
void printJSONRoute(int **route, int numberOfCities)
{
  int
    i;
 
  printf("[\n");
  for (i = 0; i < numberOfCities - 1; i++) {
    printf("  [%d, %d],\n", route[i][0], route[i][1]);
  }
  printf("  [%d, %d]\n", route[i][0], route[i][1]);
  printf("]\n");
}
 
 
int main(void)
{
  int
    n = 1000,
    numberOfCities = 51,
    mapData[][2] = {{37,52},{49,49},{52,64},{20,26},{40,30},{21,47},{17,63},{31,62},{52,33},{51,21},{42,41},{31,32},{5,25},{12,42},{36,16},{52,41},{27,23},{17,33},{13,13},{57,58},{62,42},{42,57},{16,57},{8,52},{7,38},{27,68},{30,48},{43,67},{58,48},{58,27},{37,69},{38,46},{46,10},{61,33},{62,63},{63,69},{32,22},{45,35},{59,15},{5,6},{10,17},{21,10},{5,64},{30,15},{39,10},{32,39},{25,32},{25,55},{48,28},{56,37},{30,40}},
    **route = buildRoute(mapData, numberOfCities);
  float
    initialT = 100.0,
    finalT = 0.8,
    coolingRate = 0.9;
 
  srand((unsigned)time(NULL));
 
  printf("%f\n", totalDistance(route, numberOfCities));
 
  sa(route, numberOfCities, initialT, finalT, n, coolingRate);
 
  printf("%f\n", totalDistance(route, numberOfCities));
  printJSONRoute(route, numberOfCities);
 
  return 0;
}
syntax2html

2019-08-21 I didn't do, so I looked like a "bad mood guy", and I had an experience close to the so-called "bullying". [長年日記]

When I was a junior school student, I collected stamps and ancient coins, though I was not interested in them at all.

In addition, I did "learning the line-up of Chunichi Dragons by heart" with feeling pain.

These were "booms", so called.

At that time, I thought that I was deeply interested in them, but I can say that it was a misunderstanding.

As a childhood, I could not find what I wanted to do, and I didn't have much allowance.

I am afraid that it cannot be helped that many children are going to be touched by fashion.

-----

Though I could not help it, when a boy who was at the top of my class, started to his hobby(collection of move sheets) and the classmates (mainly, boys) also became enthusiastic, I could not get with it.

I didn't do, so I looked like a "bad mood guy", and I had an experience close to the so-called "bullying".

The reason I didn't get completely bullied was I think that I was an excellent outstanding student, as an elementary school student.(It is not left at all).

And,

(1) I knew a lot of unnecessary trivia,

(2) I had a skill of argument

(3) I could operate (play) the piano.

I think that this is also due to the fact that I was a kid that was difficult to be bothered by children, and that was a ugly kid for adults.

If I had been a bad mood maker, not good at a performance, a poor grade and sports, I would have been a target of "bully"

(To be continued)


2019-08-23 ラズパイに無線LANサーバ(wlan0)と無線LANクライアント(wla1)を併設する方法 [長年日記]

ラズパイに無線LANサーバ(wlan0)と無線LANクライアント(wla1)を併設する方法

kw: WiFi2枚 USB WiFi

完成したカーネルイメージ /home/kobore/www/soft/hitachi_ride_hailing_go/20190823-WiFi2.img


==============================
0.準備しておく必要のあるもの
==============================

sudo apt install -y isc-hdcp-server

sudo apt install -y hostapd

とインストールしておく


================
1.実現したいもの
================

========================
2.wlan0, wlan1を固定する
======================= =

USBのWiFiを刺すと、wlan0, wlan1が移動してしまうので、固定する。

/etc/udev/rules.d/70-persistent-net.rules

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="b8:27:eb:ec:9c:0b", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="d0:37:45:30:71:23", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan1"

==========================
3. wlan0のIPアドレスの設定
==========================

/etc/dhcpcd.conf

interface wlan0
static ip_address=192.168.101.1/24
static routers=192.168.101.1
static domain_name_servers=192.168.101.1

sudo shutdown -r nowを実行し、OSを再起動します。

=====================================
4.isc-dhcp-serverのインストールと設定
=====================================

/etc/dhcp/dhcpd.confを次の内容にして保存します。

default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
authoritative;
subnet 192.168.101.0 netmask 255.255.255.0 {
        range 192.168.101.10 192.168.101.200;
        option broadcast-address 192.168.101.255;
        option routers 192.168.101.1;
        default-lease-time 600;
        max-lease-time 7200;
        option domain-name-servers 8.8.8.8, 8.8.4.4;
}


/etc/default/isc-dhcp-serverを編集します。

INTERFACESv4=""の箇所をINTERFACESv4="wlan0"に変更して保存します。

sudo rebootを実行し、OSを再起動します。

=============================
5.hostapdのインストールと設定
=============================

hostapdをインストールします。

$ sudo apt install hostapd -y
/etc/hostapd/hostapd.confを作成し、次の内容を記入して保存します。

ssidとwpa_passphraseの内容は、必要に応じて変更してください。ここでは「rp1」というSSIDを使用します
interface=wlan0
driver=nl80211
ssid=rp1
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_group_rekey=86400
ieee80211n=1
wme_enabled=1

/etc/default/hostapdを開き、# DAEMON_CONF=""の箇所をDAEMON_CONF="/etc/hostapd/hostapd.conf"に変更して保存します。

hostapdを実行できるよう、次のコマンドを実施します。

$ sudo systemctl unmask hostapd

============================
6.DHCPの起動タイミングの変更
============================

ネットワークよりも先にDHCPサーバーが起動する問題を回避するため、待ち時間を設定します。

/etc/init.d/isc-dhcp-serverを編集します。

log_daemon_msg “Starting $DESC” “$NAME”の次の行にsleep 10を追加して保存します。

該当箇所は、次のようになります。

log_daemon_msg “Starting $DESC” “$NAME”
sleep 10

========================
7.インターフェースの設定
========================

/etc/network/interfaces.d/wlan0を作成し、次の内容を記入して保存します。

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
      wpa-conf /etc/wpa_supplicant/wpa_supplicant_wlan0.conf

/etc/network/interfaces.d/wlan1を作成し、次の内容を記入して保存します。

auto wlan1
allow-hotplug wlan1
iface wlan1 inet dhcp
      wpa-conf /etc/wpa_supplicant/wpa_supplicant_wlan1.conf


wlan0用のWiFi接続設定を/etc/wpa_supplicant/wpa_supplicant_wlan0.confに作成します。

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP
network={
        ssid="ssid"
        psk="password"
        key_mgmt=WPA-PSK
}

wlan1用のWiFi接続設定を/etc/wpa_supplicant/wpa_supplicant_wlan1.confに作成します。

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP
network={
        ssid="iPhone"
        psk="9yniyg4p4cmh1"
}

sudo rebootを実行し、OSを再起動します。

==========
8.稼動確認
==========

ifconfigで、以下の(ような)内容が表示されればO.K.

wlan0: flags=4163  mtu 1500
        inet 192.168.101.1  netmask 255.255.255.0  broadcast 192.168.101.255
        inet6 fe80::1392:b0b4:b56a:836b  prefixlen 64  scopeid 0x20
        ether b8:27:eb:ec:9c:0b  txqueuelen 1000  (イーサネット)
        RX packets 685  bytes 61030 (59.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 148  bytes 23267 (22.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
wlan1: flags=4163  mtu 1500
        inet 172.20.10.4  netmask 255.255.255.240  broadcast 172.20.10.15
        inet6 fe80::e4a8:f21f:a6fa:111f  prefixlen 64  scopeid 0x20
        ether d0:37:45:30:71:23  txqueuelen 1000  (イーサネット)
        RX packets 28  bytes 4774 (4.6 KiB)
        RX errors 0  dropped 30  overruns 0  frame 0
        TX packets 50  bytes 8415 (8.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

PCやスマートフォンで、「rp1」というSSIDのアクセスポイントが見えて、パスワード"password"で接続できれば成功です。



2019-08-28 Mr.S's important memorandum [長年日記]

https://mail.google.com/mail/u/0/?tab=rm&ogbl#search/sakaida+.md/CllgCHrgDRrsVTddNhrDtMQZQpzwQhMtwbJzcPLZWWTtFmZhWLwRpCwlGvVbKRdQNNdCdvJJzcL

https://mail.google.com/mail/u/0/?tab=rm&ogbl#search/sakaida+.md/WhctKJVRQLzdgWJKxnGXZMhgPlkMKlhbMFKckBrtqQDDJKJLvLHGrxKTtLdKgGwLXTnlKJb

https://mail.google.com/mail/u/0/?tab=rm&ogbl#search/sakaida+.md/WhctKJVRPLZksMMKrVvhHqSbFbJSrscXCkmBqmbjnFbbscqxtkkVFcJFJFbwHXgRCsjbnLq