2022/09,江端さんの技術メモ

以前、pgr_dijkstra()で、ダイクストラの順番が壊れる という内容で悩んでいて、最終的に、

utsu_tram_db3=# SELECT seq, source, edge, x1, y1 FROM pgr_dijkstra('SELECT gid as id, source, target, cost, reverse_cost FROM ways', 2, 59, directed:=false) a INNER JOIN ways b ON (a.edge = b.gid) ORDER BY seq;

で、順列を壊さないで、ダイクストラの表示ができる、ということを書きました。

pgr_dijkstra()で算出したノードの座標を得る方法

ところが、まだ、これでも問題が発生することが分かりました。

ノード1799からノード3342のルート計算を以下のようにやってみました。

kitaya_db=# SELECT seq, source, target, x1, y1,x2,y2, agg_cost FROM pgr_dijkstra('SELECT gid as id, source, target, length_m as cost cost, reverse_cost FROM ways', 3342, 1799, directed:=false) a INNER JOIN ways b ON (a.edge = b.gid) ORDER BY seq;

まあ、こんな感じで、sourceとx1,x2を追っていって、ラストのtargetとx2,y2を拾えば、いいと分かりましたので、これで大丈夫だろう、と思ってコーディングしていました。

ところが、このノード1799からノード3342を逆転させて、ノード3342からノード1799のルート計算を以下のようにやってみました。

kitaya_db=# SELECT seq, source, target, x1, y1,x2,y2, agg_cost FROM pgr_dijkstra('SELECT gid as id, source, target, length_m as cost  cost, reverse_cost FROM ways', 1799, 3342, directed:=false) a INNER JOIN ways b ON (a.edge = b.gid) ORDER BY seq;

と、こんな感じで、sourceが出発点にならずに、targetの方が正しい並びとなってしまっています。つまり、こんな感じ。

で、これがどっちで出てくるのか分からないので、以下のようにしました。

(1)最初のノードがsourceに出てきたら、sourceベースで読み出し、
(2)最初のノードがtargetに出てきたら、targetベースで読み出す

実装はこんな感じにしました。

type LocInfo struct {
	Lon    float64
	Lat    float64
	Source int
}

 

// 江端修正版
func getDijkstraPath(dbMap *sql.DB, locInfoStart, locInfoGoal ldarp.LocInfo) ([]ldarp.LocInfo, float64) {
	log.Println("getDijkstraPath", locInfoStart, locInfoGoal)

	var path []ldarp.LocInfo // 経路 (返り値の一つ目)
	var totalDistanceKm float64

	rowsDijkstra, errDijkstra := dbMap.Query(
		"SELECT seq,source, target, x1, y1, x2, y2, agg_cost FROM pgr_dijkstra('SELECT gid as id, source, target, length_m as cost FROM ways', $1::bigint , $2::bigint , directed:=false) a INNER JOIN ways b ON (a.edge = b.gid) ORDER BY seq",
		locInfoStart.Source,
		locInfoGoal.Source)

	if errDijkstra != nil {
		log.Fatal(errDijkstra)
	}
	defer rowsDijkstra.Close()

	var agg_cost float64

	isFirstCheck := true
	isSourceCheck := true

	for rowsDijkstra.Next() {

		var x1, y1, x2, y2 float64

		var seq int
		var target int

		// まずnodeを読む
		if err := rowsDijkstra.Scan(&seq, &source, &target, &x1, &y1, &x2, &y2, &agg_cost); err != nil {
			fmt.Println(err)
		}

		// 最初の1回だけ入る
		if isFirstCheck {
			if source == locInfoStart.Source {
				isSourceCheck = true
			} else {
				isSourceCheck = false
			}
			isFirstCheck = false
		}

		var loc ldarp.LocInfo

		if isSourceCheck {
			loc.Source = source
			loc.Lon = x1
			loc.Lat = y1
		} else {
			loc.Source = target
			loc.Lon = x2
			loc.Lat = y2
		}

		loc.Source = target

		path = append(path, loc)
	}

	// ラストノードだけは手入力
	path = append(path, locInfoGoal)

	totalDistanceKm = agg_cost / 1000.0
	return path, totalDistanceKm
}

もっとクールな方法があるかもしれませんが、面倒なので、戦うのはやめました。

バグを発見したので、main()を含めた再修正版をアップしておきまます。

package main

import (
	"database/sql"
	"fmt"
	"log"
	"m/src/ldarp"

	_ "github.com/lib/pq"
)

func main() {
	db, err := sql.Open("postgres",
		"user=postgres password=password host=192.168.0.23 port=15432 dbname=tomioka_db_c sslmode=disable")
	if err != nil {
		log.Fatal("OpenError: ", err)
	}
	defer db.Close()

	var a_Point, b_Point ldarp.LocInfo
	a_Point.Source = 20
	b_Point.Source = 1
	path, dist := getDijkstraPath(db, a_Point, b_Point)

	fmt.Println("path:", path)
	fmt.Println("dist:", dist)

}

// 江端再修正版
func getDijkstraPath(dbMap *sql.DB, locInfoStart, locInfoGoal ldarp.LocInfo) ([]ldarp.LocInfo, float64) {
	log.Println("getDijkstraPath", locInfoStart, locInfoGoal)

	var path []ldarp.LocInfo // 経路 (返り値の一つ目)
	var totalDistanceKm float64

	rowsDijkstra, errDijkstra := dbMap.Query(
		"SELECT seq,source, target, x1, y1, x2, y2, agg_cost FROM pgr_dijkstra('SELECT gid as id, source, target, length_m as cost cost, reverse_cost FROM ways', $1::bigint , $2::bigint , directed:=false) a INNER JOIN ways b ON (a.edge = b.gid) ORDER BY seq",
		locInfoStart.Source,
		locInfoGoal.Source)

	if errDijkstra != nil {
		log.Fatal(errDijkstra)
	}
	defer rowsDijkstra.Close()

	var agg_cost float64

	var loc ldarp.LocInfo
	var x1, y1, x2, y2 float64
	var seq int
	var target int
	var source int

	isFirstCheck := true
	isSourceCheck := true

	for rowsDijkstra.Next() {

		// まずnodeを読む
		if err := rowsDijkstra.Scan(&seq, &source, &target, &x1, &y1, &x2, &y2, &agg_cost); err != nil {
			fmt.Println(err)
		}

		// 最初の1回だけチェックのために入る これについては、https://wp.kobore.net/江端さんの技術メモ/post-7668/を参照のこと
		// もし rowsDijkstra.Scanで最初のsource値を読みとり、locInfoStart.Source の値と同じであれば、x1,y1をベースとして、異なる値であれば、x2,y2をベースとする

		if isFirstCheck {
			if source == locInfoStart.Source {
				isSourceCheck = true // x1, y1をベースとする処理になる
			} else {
				isSourceCheck = false // x2,y2をベースとする処理になる
			}
			isFirstCheck = false // 最初の1回をチェックすることで、2回目はこのループには入らなくなる
		}

		//var loc ldarp.LocInfo

		if isSourceCheck { // x1, y1をベースとする処理
			loc.Source = source
			loc.Lon = x1
			loc.Lat = y1
		} else { // x2,y2をベースとする処理
			loc.Source = target
			loc.Lon = x2
			loc.Lat = y2
		}
		path = append(path, loc)
	}

	// ラストノードだけは手入力 (ここは引っくり返す)
	if isSourceCheck { // x1, y1をベースとする処理
		loc.Source = target
		loc.Lon = x2
		loc.Lat = y2
	} else { // x2,y2をベースとする処理
		loc.Source = source
		loc.Lon = x1
		loc.Lat = y1
	}

	path = append(path, loc)

	totalDistanceKm = agg_cost / 1000.0
	return path, totalDistanceKm
}

 

2022/09,江端さんの技術メモ

パワポで、バックグランド黒、白い線を複数コピペを繰り返す

SAIで、エラブラシで発光を付ける

線をぼかして、完成

2022/09,江端さんの技術メモ

信者獲得&洗脳シミュレーションプログラム

package main

import (
	"fmt"
	"math/rand"
)

type person struct {
	number             int     // 番号
	mental_strength    float64 // 勧誘に屈しない強さ
	religious_devotion float64 // 信仰力
	church             int     //教会フラグ
}

var p_array []*person // personの配列2
var (
	p_num = 0
)

func person_create() *person {
	p := new(person)
	p.number = p_num
	p_num++                            // 生成された順番に番号を付けていく
	p.mental_strength = rand.Float64() // 勧誘を断わる強さ
	p.religious_devotion = 0           // 信仰力最初は"0"
	p.church = 0                       // 教会フラグ
	p_array = append(p_array, p)       // 配列に放り込む

	return p
}

func (p *person) person_destroy() {
	for index, v := range p_array {
		if v == p {
			p_array = append(p_array[:index], p_array[index+1:]...)
			break
		}
	}
	p = nil //これでいいのかな? ガーベージコレクションが消してくれる、と聞いているが
}

type agent struct {
	number           int     // 番号
	invitation_power float64 // 勧誘力
}

var a_array []*agent // agentの配列
var (
	a_num = 0
)

func agent_create() *agent {
	a := new(agent)
	a.number = a_num
	a_num++                                       // 生成された順番に番号を付けていく
	a.invitation_power = 0.3 + 0.7*rand.Float64() // 勧誘力
	a_array = append(a_array, a)                  // 配列に放り込む
	return a
}

func (a *agent) agent_destroy() {
	for index, v := range a_array {
		if v == a {
			a_array = append(a_array[:index], a_array[index+1:]...)
			break
		}
	}
	a = nil //これでいいのかな? ガーベージコレクションが消してくれる、と聞いているが
}

func (p *person) meet_agent(a *agent) {
	if p.mental_strength < a.invitation_power {
		p.religious_devotion += a.invitation_power * 0.1 // エージェントの説得によって信仰心が微増
		p.mental_strength -= a.invitation_power * 0.1    // エージェントの説得によって心理障壁が微減
		if p.religious_devotion > 1.0 {
			p.religious_devotion = 1.0
		}
		if p.mental_strength < 0.0 {
			p.mental_strength = 0.0
		}

	}

}

func main() {
	for i := 0; i < 1000; i++ {
		person_create()
	}

	fmt.Println("======p_array=========")

	for _, p := range p_array {
		fmt.Println(p.number, ",", p.mental_strength, ",", p.religious_devotion)
	}

	for i := 0; i < 5; i++ {
		agent_create()
	}

	fmt.Println("======a_array=========")

	for _, a := range a_array {
		fmt.Println(a.number, ",", a.invitation_power)
	}

	for i := 0; i < 365; i++ { // 1年間の勧誘
		for _, p := range p_array {
			//fmt.Println(index, ":", v, v.number, v.mental_strength)
			for _, a := range a_array {
				if rand.Float64() < 0.001 {
					p.meet_agent(a)
				}
			}
		}
	}

	fmt.Println("=====p_array after 365days==========")

	for _, p := range p_array {
		fmt.Println(p.number, ",", p.mental_strength, ",", p.religious_devotion)
	}

	fmt.Println("====count2===========")
	count := 0
	for _, p := range p_array {
		if p.religious_devotion > 0.2 {
			p.church = 1 //教会フラグを"1"に変項
			count++
			fmt.Println(p.religious_devotion)
		}
	}
	fmt.Println(count)

	for i := 0; i < 365; i++ { // 2年目の勧誘
		for _, p := range p_array {
			//fmt.Println(index, ":", v, v.number, v.mental_strength)
			for _, a := range a_array {
				if p.church == 1 && rand.Float64() < 0.005 {
					p.meet_agent(a)
				}
			}
		}
	}

	fmt.Println("=====p_array after 365days x 2==========")

	for _, p := range p_array {
		if p.church == 1 {
			fmt.Println(p.number, ",", p.mental_strength, ",", p.religious_devotion)
		}
	}

}

出力結果(エクセルファイル)  → cult.xlsx

2022/09,江端さんの技術メモ

Go言語でエージェントシミュレータを作るのに必要なパーツを作っています。

エージェントをオブジェクト風に作って、配列にいれて、終了したら、エージェントを消滅する。

package main

import (
	"fmt"
	"math/rand"
)

type person struct {
	number          int     // 番号
	mental_strength float64 // 勧誘に屈しない強さ
}

var p_array []*person // personの配列

func person_create(num int) *person {
	p := new(person)
	p.number = num
	p.mental_strength = rand.Float64() // 勧誘を断わる強さ
	p_array = append(p_array, p)       // 配列に放り込む
	return p
}

func (p *person) person_destroy() {

	for index, v := range p_array {
		if v == p {
			fmt.Println("hit")
			p_array = append(p_array[:index], p_array[index+1:]...)
			break
		}

	}

	p = nil //これでいいのかな?
}

func main() {
	_ = person_create(0)
	p1 := person_create(1)
	p2 := person_create(2)
	_ = person_create(3)

	for index, v := range p_array {
		fmt.Println(index, ":", v, v.number, v.mental_strength)
	}

	p2.person_destroy()

	for index, v := range p_array {
		fmt.Println(index, ":", v, v.number, v.mental_strength)
	}

	p1.person_destroy()

	for index, v := range p_array {
		fmt.Println(index, ":", v, v.number, v.mental_strength)
	}

}

■出力結果

PS C:\Users\ebata\cult> go run main.go
0 : &{0 0.6046602879796196} 0 0.6046602879796196
1 : &{1 0.9405090880450124} 1 0.9405090880450124
2 : &{2 0.6645600532184904} 2 0.6645600532184904
3 : &{3 0.4377141871869802} 3 0.4377141871869802
hit
0 : &{0 0.6046602879796196} 0 0.6046602879796196
1 : &{1 0.9405090880450124} 1 0.9405090880450124
2 : &{3 0.4377141871869802} 3 0.4377141871869802
hit
0 : &{0 0.6046602879796196} 0 0.6046602879796196
1 : &{3 0.4377141871869802} 3 0.4377141871869802

2022/09,江端さんの忘備録

一昨日、たまたま、Amazonプライムで「十二単衣を着た悪魔」という映画を、なにげなく視聴していたのですが、『これは、久々のヒットだ』と思いました。

The day before yesterday, I happened to be casually watching a movie called "The Devil Wears Twelve Clothes" on Amazon Prime, and I thought, 'This is a hit for a long time'.

早速、原作を求めて、コミック、アニメと探したのですが、見つかりません。

I immediately searched for the original story, comic and anime, but could not find it.

もしかしたら、と思いつつ、書籍の方を探してみたら ―― 当たりました。

I looked for the book to see if it might be possible, and I hit it.

で、そのまま図書館に予約を出したら、即日でやってきて、何年かぶりに「一日での一気読み」をやってしまいました。

After the reservation to the city library, the book came to me in the same day, and for the first time in years, I did a "read in one day".

-----

私は、源氏物語の登場人物の、ほぼ全員を把握しています。

I know almost all of the characters in The Tale of Genji.

これは、私が源氏物語の研究に精通しているからではありません。

This is not because I am an expert in the study of the Tale of Genji.

ティーンエイジャの頃に、大和和紀さんのコミック「あさきゆめみし」を読み込んだだけです。

I just read Kazuki Yamato's comic "Asaki Yumemishi" when I was a teenager.

「あさきゆめみし」のお陰で、私の源氏物語の『通り一遍の知識』は、万全といっても過言ではありません。

Thanks to "Asaki Yumemishi," my "cursory knowledge" of The Tale of Genji is complete.

-----

それにしても、このコンテンツ、「時空間モノ」ということ以上に、『弘徽殿女御を、こう描くかぁ・・・』と、久々に目から鱗の落ちる思いです。

This content is a good "time-space thing" however, it is also a "how to depict Lady Koukiden in this way..." It has been a long time since I have seen the light

基本的に、私、心情的に「アンチ光源氏」なのですが、

Basically, I am emotionally "anti-Hikaru Genji, and

―― 努力は才能を越えない

"Ability counts for more than effort."

を、再度思い知らされるコンテンツでした。

The phrase reminder me it again.

"誰でも自分を自覚するべきだ。でないと。……見ている側が馬鹿馬鹿しい"

 

 

2022/09,江端さんの技術メモ

さくらのレンタルサーバでの「ベーシック認証」は、自力でやらず、サーバーコントロールパネルを使うこと

特定のディレクトリのみベーシック認証を実施したかったのですが、

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

から逃げられず、どうして良いのか分からなかったのですが、どうも、これ、プロバイダ側の原因(仕様変更)らしいと分かってきました。

で、今、動いたようなので、忘れない内に、私の為に、メモのみ残しておきます。

これで,".htpassword"が生成されます。

これを操作すると(内容は忘れた)、".htaccess"が生成されます。

いずれにしても、「手動で作る」ことは諦めた方がいいです。

以上

 

 

2022/09,未分類,江端さんの技術メモ

ホームページを丸ごとダウンロードできる便利ツールHTTrack(WinHTTrack)の使い方

EE Times Japan風のスタイルサンプル


<!-- globalStylesheet -->

<link rel="stylesheet" href="https://www.itmedia.co.jp/css/ee/base.css?201908291653" type="text/css" media="all">
<link rel="stylesheet" href="https://www.itmedia.co.jp/css/ee/ad.css?202106291147" type="text/css" media="all">
<link rel="stylesheet" href="https://www.itmedia.co.jp/css/ee/article.css?202208011700" type="text/css" media="all">

<!-- /globalStylesheet -->

<div class="lpanIn">


<script type="text/javascript">
var str = document.title.replace(/\<\!\-\-EDIT START\-\-\>/g,'').replace(/\<\!\-\-EDIT END\-\-\>/g,'').replace(' - EE Times Japan','');
str = cutString(str,50);
document.write(str);
</script>

</div>
</div>
</div>
</div>
</div>

</div>


<div id="masterContents"><div id="globalContents">
<div id="masterMain">

<!---->


<div id="tmplNews" class="tmplArticle"><div id="tmplNewsIn" class="tmplArticleIn">

	


<!--EDIT START-->
<!--EDIT END-->



<div id="cmsTitle"><div class="inner">
<h1 class="title"><span class="title__maintext">老後を生き残る「戦略としての信仰」は存在するのか</span><i class="title__delimiter">:</i><i class="title__subtitle">「お金に愛されないエンジニア」のための新行動論(6)</i><span class="title__pagenumber">(4/12 ページ)</span></h1>
</div></div>
<div id="tmplMark"></div>


<div id="cmsAbstract"><div class="inner"><h2></h2></div></div>


<!---->

<div id="cmsByline"></div>
<div id="cmsByline"></div>


<div id="cmsByline"><div class="inner" id="byline"><b>[</b><b>]</b></div></div>
<div id="cmsByline"><div class="inner" id="byline"><b>[</b>江端智一,<b>EE Times Japan]</b></div></div>



<!-- cmsHoleBodyWrapStart -->
<div id="cmsBody"><div class="inner">

<script>
(function(){
	var d = document;
	var date = d.getElementById('cmsDate');
	var type = d.getElementById('cmsType');
	var abstract = d.getElementById('cmsAbstract');
	var byline = d.getElementById('cmsByline');
	// 位置を移動
	byline.parentNode.insertBefore(date,byline);
	// 要素を削除
	type.parentNode.removeChild(type);
	abstract.parentNode.removeChild(abstract);
})();
</script>



<link rel="stylesheet" href="https://www.itmedia.co.jp/css/socialbutton.css?202001221022">
<script>
var msbBtnLoadScript = [];
</script>
<script src="https://eetimes.itmedia.co.jp/js/socialbutton.js?202111161930"></script>
<div id="masterSocialbuttonTop" class="masterSocialbutton"><div class="msbOut" id="msbTopOut"></div></div>




<!-- BCP Text -->


<div id="cmsMark"><!-- null for itmedia-->
</div>
<!-- cmsBodyCtrlTop -->
<div class="ctrl">
<span id="prev"><a href="news047_3.html">前のページへ</a></span>
<span id="numb"><a href="news047.html">1</a>|<a href="news047_2.html">2</a>|<a href="news047_3.html">3</a>|<strong>4</strong>|<a href="news047_5.html">5</a>|<a href="news047_6.html">6</a>|<a href="news047_7.html">7</a>|<a href="news047_8.html">8</a>|<a href="news047_9.html">9</a>|<a href="news047_10.html">10</a>|<a href="news047_11.html">11</a>|<a href="news047_12.html">12</a></span>
<span id="next"><a href="news047_5.html">次のページへ</a></span>
</div>

<!-- cmsBodyMainStart -->
<!-- cxenseparse_start -->
<div class="subscription">
<a name="point2"></a>
<h4>私(江端)がカルト宗教(江端教)の教祖になった件</h4>
<p> さて、キリスト教系のカルト宗教団体の多くは、キリスト教の根幹とも言える、この"原罪"ストーリーに、壮大なラクガキ・・・もとい、上書きを施します。これらのカルト宗教に見られる「上書き」パターンには以下のようなものがあります(というか、私が知る限り、『これしかない』という感じです)。</p>
<p> カルト宗教団体や、その教祖のイメージをしやすくするために、『<strong>私(江端)がカルト宗教(江端教)の教祖になった件</strong>』、という架空の話で説明を行います。</p>
<p> まず、教祖である私は、原作である失楽園での、「アダムとイブによるリンゴ食」のストーリーを、ヘビ(ルシファー)とイブの性交(SEX)と、さらに、イブとアダムとの性交(SEX)という、「ヘビとアダムとイヴの3P(Three persons SEX)」が実施された、という「上書き」を施します。これによって、精神的または肉体的な純潔が犯された(堕落した)という概念を挿入しました。</p>
<p> 次に、私は、『イエス・キリストの救済は、万能ではなかった』、という「上書き」を加えます ―― といっても、イエス・キリストの働きを全面的に否定するのではなく、精神的または肉体的な純潔という2つの純潔のうち、<strong>「精神面」だけは解決してくれた</strong>、というストーリーに改ざんします。</p>
<p> イエス・キリストを全面否定すると、信者が集まりにくくなると考えたので、ここは、イエス・キリストを活用する方向でストーリーを作りました。</p>
<p> しかし、<strong>肉体的な純潔は、まだ回復されていない</strong>、という課題を残しつつ、ついに、ここに私(江端)が登場するのです。</p>
<!--CAP-->
<div id="col600c"><a name="mm220831_money02_w570.jpg"></a><img src="https://image.itmedia.co.jp/ee/articles/2208/31/mm220831_money02_w570.jpg" width="570" height="981"></div>
<!--CAPEND-->
<p> <strong>“メシア the final” こそが、この私江端智一、偉大なる江端、『<span class="cmsFontsize1">エバ・カンターレ</span>』です。</strong></p>
<p> 以上をまとめますと ―― イエス・キリスト製ワクチンは、”魂(スピリッツ)の原罪”には効果はあったが、<strong>肉体(フィジカル)の原罪には、その効力が及んでいない</strong>、という、<strong>壮大なシナリオ変更をぶっこむ</strong>のです。この肉体版”原罪”のワクチンとなるのが、この私、エバ・カンターレなのです。</p>
<p> 私(江端)は、『<strong>イエス・キリストは完全な”原罪”ウイルス向けワクチンを提供していない</strong>』と、キリスト教に対する強烈なディスリスペクトをかました上で、<strong>自分(江端)こそが最終救済者(メシア the final)であると言い切ります</strong>。もちろん、これは、世界中のキリスト教徒全てにケンカを売る行為です<sup>*)</sup>。</p>
<p><span class="cmsFontsize-1">*)ただ、世界中のカルトの教祖のほぼ全てが、「自分こそが”メシアthe final”」と主張しているので、逆に、「ありふれている」と言えるかもしれませんが。</span></p>
<!--CAP-->
<div id="col600c"><a name="mm220831_money02a_w570.jpg"></a><img src="https://image.itmedia.co.jp/ee/articles/2208/31/mm220831_money02a_w570.jpg" width="570" height="428"></div>
<!--CAPEND-->
<p> 江端教の目的が、肉体向け”原罪”に対抗するワクチン接種行為と考えるわけです。</p>
<p> しかし、肉体向け"原罪"の消滅は、mRNAのようなワクチン接種では実現できません。そこで、私は、AI技術の一つである、遺伝的アルゴリズム<sup>*)</sup>のアプローチ、すなわち、人為的なエリート製造戦略で、この問題の解決を試みます。</p>
<p><span class="cmsFontsize-1">*関連記事:「<A HREF="https://eetimes.itmedia.co.jp/ee/articles/1701/31/news031.html" target="_blank">抹殺する人工知能 ~ 生存競争と自然淘汰で、最適解にたどりつく</A>」</span></p>
<p> つまり、<strong>肉体向け”原罪”をうまいこと消滅できる組み合わせのカップルを作る</strong>のです。『そんなこと、どうやってできるのか』などとは、考えてはなりません。</p>
<p> 私はたった一人で、誰にも相談せずに、この組み合わせをコンピュータと直感でデザインするのです。しかし、1組、2組程度をちんたらやっていたら、人類の救済などできません。</p>
<p> ですので、カップルを、数千から数万単位で同時に量産するのです。その上、私は、男女の顔写真と全身写真”だけ”で、<A HREF="https://eetimes.itmedia.co.jp/ee/articles/1804/27/news093_2.html" target="_blank">ニューラルネットワーク</A>と、<A HREF="https://eetimes.itmedia.co.jp/ee/articles/1711/30/news019_2.html" target="_blank">最適化アルゴリズム</A>を使ってマッチングさせます。</p>
<p> 私はコンピュータを使った組み合わせ問題のエキスパートでもありますので、この問題の困難性を完璧に理解しています。恐らく、完璧な量子コンピュータが開発されたとしても、この組み合わせを完成させるのには、宇宙の年齢を、宇宙の年齢分繰り返しても、全然足りないくらいの時間が必要です<sup>*)</sup>。</p>
<p><span class="cmsFontsize-1">*)「NP困難問題」でググってみてください。</span></p>
<p> しかし、忘れてなりません。私は、最終救済者、”メシア the final”なのです。<strong>私のコンピュータの中には、神が常駐しており、私には、計算中のコンピュータから、常に神の声が聞こえてくるのです</strong>。</p>
<p> このように、この私は、肉体版”原罪”を消滅させうる超高度な医学的(遺伝子学)組み合わせを、写真だけを使って、膨大(という言葉では語れないくらいの膨大)な数でデザインします。</p>
<p> この程度のこと、”メシア the final”である私にとっては、ピース・オブ・ケーキ(朝飯前)です。</p>
<p> 人類は、最終救済のためであれば、自由恋愛やら、出会いの場やら、合コンやら、結婚相談所やら、そのような些事(さじ)に関わっている暇はありません。</p>
<p> 神の声を聞くことのできる唯一のメシアである私は、堕落した近代の<strong>自由恋愛結婚観を完全否定</strong>して、現実世界において、豪快かつ壮大な数の遺伝的アルゴリズムを地上で実現しなければならないという使命があるのです ―― つまり、一斉集団結婚です<sup>*)</sup>。</p>
<p><span class="cmsFontsize-1">*)純潔を守るという名目の、「村の中のみで閉じた結婚制度」、あるいは、「一夫多妻」「一妻多夫」などのような形態でも同じ効果を得られます。</span></p>
<p> すなわち、江端教においては、肉体版"原罪"を消滅させうる手段として、一斉集団結婚は、絶対に避けて通ることができない一大イベントなのです。</p>
<div id="notice"><a href="news047_5.html">「江端原理」通称”エバタ・プリンシプル”を説明する</a></div>
</div><!-- subscription end -->

<!-- cxenseparse_end -->

<!-- cmsBodyMainEnd -->

<!-- cmsBodyRelated -->
<div class="ctrl">
<span id="prev"><a href="news047_3.html">前のページへ</a></span>
<span id="numb"><a href="news047.html">1</a>|<a href="news047_2.html">2</a>|<a href="news047_3.html">3</a>|<strong>4</strong>|<a href="news047_5.html">5</a>|<a href="news047_6.html">6</a>|<a href="news047_7.html">7</a>|<a href="news047_8.html">8</a>|<a href="news047_9.html">9</a>|<a href="news047_10.html">10</a>|<a href="news047_11.html">11</a>|<a href="news047_12.html">12</a></span>
<span id="next"><a href="news047_5.html">次のページへ</a></span>
</div>

2022/09,江端さんの技術メモ

/*

golangで時刻(time)情報を生成して、その情報をpostgresqlに格納して、さらに読み出す実験

テスト用DB環境の作り方

C:\Users\ebata>psql -U postgres -p 15432
Password for user postgres:
psql (13.4, server 12.5 (Debian 12.5-1.pgdg100+1))
Type "help" for help.

postgres=# create database agent_db;
CREATE DATABASE

postgres-# \c agent_db
psql (13.4, server 12.5 (Debian 12.5-1.pgdg100+1))
You are now connected to database "agent_db" as user "postgres".

agent_db-# create table LocMessage(
agent_db(# ID     int,
agent_db(# dt     timestamp,
agent_db(# Lat    double precision,
agent_db(# Lng    double precision,
agent_db(# TYPE   varchar(10),
agent_db(# POPUP  int
agent_db(# );

agent_db=# \dt
           List of relations
 Schema |    Name    | Type  |  Owner
--------+------------+-------+----------
 public | locmessage | table | postgres
(1 row)


agent_db=# select * from locmessage;
 id | dt | lat | lng | type | popup
----+----+-----+-----+------+-------
(0 rows)

と、まあ、こんな感じ

*/

package main

import (
	"database/sql"
	"fmt"
	"log"
	"time"

	_ "github.com/lib/pq" // ←これを追記
)

func main() {

	db, err := sql.Open("postgres",
		"user=postgres password=password host=localhost port=15432 dbname=agent_db sslmode=disable")
	if err != nil {
		log.Fatal("OpenError: ", err)
	}
	defer db.Close()

	ins, err := db.Prepare("insert into locmessage(id,dt,lat,lng,type,popup) VALUES($1,$2,$3,$4,$5,$6)")
	if err != nil {
		log.Fatal("db.Exec Error: ", err)
	}

	a := 1
	b := time.Now()
	c := 139.02
	d := 38.02
	e := 1
	f := 1

	ins.Exec(a, b, c, d, e, f)

	///// 書き込みここまで
	// 書き込まれたデータはこんな感じになっている (2回プログラムを実施)
	/*
		agent_db=# select * from locmessage;
		 id |             dt             |  lat   |  lng  | type | popup
		----+----------------------------+--------+-------+------+-------
		  1 | 2022-09-15 23:54:36.877274 | 139.02 | 38.02 | 1    |     1
		  1 | 2022-09-15 23:55:16.574776 | 139.02 | 38.02 | 1    |     1
		(2 rows)
	*/
	// さて、このDBからどうやって、時間情報を取り出すか?

	rows, err := db.Query("select dt from locmessage")
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	var dt time.Time

	for rows.Next() {
		if err := rows.Scan(&dt); err != nil {
			fmt.Println(err)
		}

		fmt.Println(dt)

		// 出力結果が、こんな感じになって、ちょっと変 "+0000 +0000"は、いらん
		/*
			2022-09-15 23:54:36.877274 +0000 +0000
			2022-09-15 23:55:16.574776 +0000 +0000
			2022-09-16 00:06:18.870051 +0000 +0000
			2022-09-16 00:12:51.251972 +0000 +0000
			.....
			2022-09-16 13:57:46.704896 +0000 +0000
		*/

		// こんな感じにすれば、整数などでデータ取り出せる
		fmt.Println(dt.Date())   // e.g 2022 September 16
		fmt.Println(dt.Clock())  // 13 57 46
		fmt.Println(dt.Minute()) // 57
		fmt.Println(dt.Hour())   // 13
		fmt.Println(dt.Day())    // 16

	}

}

こんだけのことがやりたかっただけなのに、"golang" "postgresql", "timestamp", "time.Time"で検索しても、ドンピシャの情報が出てこないんですよ、不思議なことに。

2022/09,江端さんの技術メモ

dis: 0.2839182387773051
dis: 0.09663299157559467
dis: 1.2640838214822172
dis: 0.2725675930110564
fatal error: concurrent map iteration and map write
goroutine 26 [running]:
runtime.throw({0x432b38, 0xc000292000})
        c:/go/src/runtime/panic.go:1198 +0x76 fp=0xc00033d858 sp=0xc00033d828 pc=0x196416
runtime.mapiternext(0x48a620)
        c:/go/src/runtime/map.go:858 +0x4eb fp=0xc00033d8c8 sp=0xc00033d858 pc=0x16f8cb
main.echo3({0x48f558, 0xc00013e2a0}, 0x0)
---
さて、やっつけますか。
「mapの競合状態のはなし」のページを参考にさせて頂き、新しく作ったmapが悪さをしているとアタリをつけました。
で、当初、sync.Mutexでロックしていたのですが、デッドロックが発生してしまいました。
そこで、sync.RWMutexに変更したところ、デッドロックが発生しなくなりました。
―― というのは気のせいのようで、RWMutex でも メソッドにLock Unlockを使えば、Mutexと同じらしいので、たまたま偶然だったようです。
RWMutexのウリは、
RLock : 読み取り用のロック。RLock同士はブロックせず、Lockのみがブロックされる。解除時は RUnlockを使う
Lock : Mutexと同じロック。RLock, Lock双方をブロックする。
のようです。今回は、読み出し中に、書き込みや削除処理が走ることがあったのですが、読み出し場所が一箇所だけだったので、普通に、Lock, Unlockを使用することにしました。
これでサーバがダウンすることはなくなりました。
以上

2022/09,江端さんの技術メモ

C言語によるファジィ(Fuzzy)推論コード

をGo言語に移植してみました。

で、できるだけ、

「GO言語でクラスっぽいことをする」をレビューする

に近づけてみました。

コメントのPrint分は、C++のを残しています(面倒だったので)。あとenum型がないので、テキトーに文字列を使うことにしました。

以前のコードには、豪快なバグがありましたので、ソックリ差し替えします。

設定条件は以下の通りです(テーブルの内容は、負荷量です)

package main

import (
	"fmt"
	"os"
)

func max_2(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func min_2(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

type condition_MF3 struct { // condition_MF3の基底クラス
	center  float64
	width   float64
	express string
}

func new_condition_MF3(_center, _width float64, _express string) *condition_MF3 {
	c3 := new(condition_MF3)
	c3.center = _center
	c3.width = _width
	c3.express = _express
	return c3
}

// 前件部メンバーシップ関数(山3つ)クラス
func (c3 *condition_MF3) func_X(_x float64) float64 {
	// x,yは、メンバーシップ関数上の座標を示す
	x := _x
	y := 0.0 // yの値は、必ず0以上1以下になる

	if c3.express == "LESS" {
		if x <= c3.center-c3.width {
			y = 1.0
		} else if x <= c3.center {
			y = -1.0 / c3.width * (x - c3.center)
		} else {
			y = 0.0
		}
	} else if c3.express == "COMMON" {
		if x <= c3.center-c3.width {
			y = 0.0
		} else if x <= c3.center {
			y = 1.0/c3.width*(x-c3.center) + 1.0
		} else if x <= c3.center+c3.width {
			y = -1.0/c3.width*(x-c3.center) + 1.0
		} else {
			y = 0.0
		}
	} else if c3.express == "MORE" {
		if x <= c3.center {
			y = 0.0
		} else if x <= c3.center+c3.width {
			y = 1.0 / c3.width * (x - c3.center)
		} else {
			y = 1.0
		}
	} else {
		fmt.Println("MF3: wrong expression")
		os.Exit(1)
	}
	return y
}

type condition_MF5 struct { // condition_MF5の基底クラス
	center  float64
	width   float64
	express string
}

func new_condition_MF5(_center, _width float64, _express string) *condition_MF5 {
	c5 := new(condition_MF5)
	c5.center = _center
	c5.width = _width
	c5.express = _express
	return c5
}

func (c5 *condition_MF5) func_X(_x float64) float64 {
	// 前件部メンバーシップ関数(山5つ)クラス
	// x,yは、メンバーシップ関数上の座標を示す
	x := _x
	y := 0.0 // yの値は、必ず0以上1以下になる

	if c5.express == "LESSLESS" {
		if x <= c5.center-2.0*c5.width {
			y = 1.0
		} else if x <= c5.center-c5.width {
			y = -1.0/c5.width*(x-(c5.center-2.0*c5.width)) + 1.0
		} else {
			y = 0.0
		}
	} else if c5.express == "LESS" {
		if x <= c5.center-2.0*c5.width {
			y = 0.0
		} else if x <= c5.center-c5.width {
			y = 1.0/c5.width*(x-(c5.center-c5.width)) + 1.0
		} else if x <= c5.center {
			y = -1.0/c5.width*(x-(c5.center-c5.width)) + 1.0
		} else {
			y = 0.0
		}
	} else if c5.express == "COMMON" {
		if x <= c5.center-c5.width {
			y = 0.0
		} else if x <= c5.center {
			y = 1.0/c5.width*(x-c5.center) + 1.0
		} else if x <= c5.center+c5.width {
			y = -1.0/c5.width*(x-c5.center) + 1.0
		} else {
			y = 0.0
		}
	} else if c5.express == "MORE" {
		if x <= c5.center {
			y = 0.0
		} else if x <= c5.center+c5.width {
			y = 1.0/c5.width*(x-(c5.center+c5.width)) + 1.0
		} else if x <= c5.center+2.0*c5.width {
			y = -1.0/c5.width*(x-(c5.center+c5.width)) + 1.0
		} else {
			y = 0.0
		}
	} else if c5.express == "MOREMORE" {
		if x <= c5.center+c5.width {
			y = 0.0
		} else if x <= c5.center+2.0*c5.width {
			y = 1.0/c5.width*(x-(c5.center+2.0*c5.width)) + 1.0
		} else {
			y = 1.0
		}
	} else {
		fmt.Println("MF5 func_X(): wrong expression")
		os.Exit(1)
	}

	return y
}

/////////////////////////////

type action_MF5 struct { // condition_MF5の基底クラス
	center  float64
	width   float64
	express string
	x       float64
	y       float64
}

func new_action_MF5(_center, _width float64, _express string) *action_MF5 {
	a5 := new(action_MF5)
	a5.center = _center
	a5.width = _width
	a5.express = _express

	if a5.express == "LESSLESS" {
		a5.x = a5.center - 2.0*a5.width
	} else if a5.express == "LESS" {
		a5.x = a5.center - a5.width
	} else if a5.express == "COMMON" {
		a5.x = a5.center
	} else if a5.express == "MORE" {
		a5.x = a5.center + a5.width
	} else if a5.express == "MOREMORE" {
		a5.x = a5.center + 2.0*a5.width
	} else {
		fmt.Println("new_action_MF5: wrong scale expression")
		os.Exit(-1)
	}

	a5.y = 0.0

	return a5
}

// 後件部メンバーシップ関数(山3つ)クラス
func (a5 *action_MF5) func_Y() float64 {
	// x,yは、メンバーシップ関数上の座標を示す

	return a5.y
}

func (a5 *action_MF5) func_Max(b float64) {
	a5.y = max_2(b, a5.y)
}

func (a5 *action_MF5) func_X() float64 {
	return a5.x
}

func complain_reasoning(dis, age float64) float64 {

	// Walking(前件部)
	Walk_Less := new_condition_MF3(1.4, 0.4, "LESS")
	Walk_Common := new_condition_MF3(1.4, 0.4, "COMMON")
	Walk_More := new_condition_MF3(1.4, 0.4, "MORE")

	// Age(前件部)
	Age_LessLess := new_condition_MF5(42, 15, "LESSLESS")
	Age_Less := new_condition_MF5(42, 15, "LESS")
	Age_Common := new_condition_MF5(42, 15, "COMMON") // 中央が 42歳
	Age_More := new_condition_MF5(42, 15, "MORE")
	Age_MoreMore := new_condition_MF5(42, 15, "MOREMORE")

	// Complain(後件部)
	Complain_LessLess := new_action_MF5(0.5, 0.25, "LESSLESS") // 不満の中央値が0.5   0.0/0.25/0.50/0.75/1.00 の5段階

	Complain_Less := new_action_MF5(0.5, 0.25, "LESS")
	Complain_Common := new_action_MF5(0.5, 0.25, "COMMON")
	Complain_More := new_action_MF5(0.5, 0.25, "MORE")
	Complain_MoreMore := new_action_MF5(0.5, 0.25, "MOREMORE")

	// [ルール00] 歩行距離:少0 年令:子供0
	Rule00 := min_2(Walk_Less.func_X(dis), Age_LessLess.func_X(age))
	Complain_LessLess.func_Max(Rule00) // 後件部は上書きされていく
	//fmt.Println("Rule00", Rule00)

	// [ルール01] 歩行距離:少0 年令:若年1
	Rule01 := min_2(Walk_Less.func_X(dis), Age_Less.func_X(age))
	Complain_LessLess.func_Max(Rule01) // 後件部は上書きされていく
	//fmt.Println("Rule01", Rule01)

	// [ルール02] 歩行距離:少0 年令:壮年2
	Rule02 := min_2(Walk_Less.func_X(dis), Age_Common.func_X(age))
	Complain_Common.func_Max(Rule02) // 後件部は上書きされていく
	//fmt.Println("Rule02", Rule02)

	// [ルール03] 歩行距離:少0 年令:高齢3
	Rule03 := min_2(Walk_Less.func_X(dis), Age_More.func_X(age))
	Complain_Common.func_Max(Rule03) // 後件部は上書きされていく
	//fmt.Println("Rule03", Rule03)

	// [ルール04] 歩行距離:少0 年令:老齢4
	Rule04 := min_2(Walk_Less.func_X(dis), Age_MoreMore.func_X(age))
	Complain_More.func_Max(Rule04) // 後件部は上書きされていく
	//fmt.Println("Rule04", Rule04)

	// [ルール10] 歩行距離:普通1 年令:子供0
	Rule10 := min_2(Walk_Common.func_X(dis), Age_LessLess.func_X(age))
	Complain_LessLess.func_Max(Rule10) // 後件部は上書きされていく
	//fmt.Println("Rule10", Rule10)

	// [ルール11] 歩行距離:普通1 年令:若年1
	Rule11 := min_2(Walk_Common.func_X(dis), Age_Less.func_X(age))
	Complain_Less.func_Max(Rule11) // 後件部は上書きされていく
	//fmt.Println("Rule11", Rule11)

	// [ルール12] 歩行距離:普通1 年令:壮年2
	Rule12 := min_2(Walk_Common.func_X(dis), Age_Common.func_X(age))
	Complain_Common.func_Max(Rule12) // 後件部は上書きされていく
	//fmt.Println("Rule12", Rule12)

	// [ルール13] 歩行距離:普通1 年令:高齢3
	Rule13 := min_2(Walk_Common.func_X(dis), Age_More.func_X(age))
	Complain_More.func_Max(Rule13) // 後件部は上書きされていく
	//fmt.Println("Rule13", Rule13)

	// [ルール14] 歩行距離:普通1 年令:老齢4
	Rule14 := min_2(Walk_Common.func_X(dis), Age_MoreMore.func_X(age))
	Complain_MoreMore.func_Max(Rule14) // 後件部は上書きされていく
	//fmt.Println("Rule14", Rule14)

	// [ルール20] 歩行距離:多2 年令:こども0
	Rule20 := min_2(Walk_More.func_X(dis), Age_LessLess.func_X(age))
	Complain_Less.func_Max(Rule20) // 後件部は上書きされていく
	//fmt.Println("Rule20", Rule20)

	// [ルール21] 歩行距離:多2 年令:若年1
	Rule21 := min_2(Walk_More.func_X(dis), Age_Less.func_X(age))
	Complain_Common.func_Max(Rule21) // 後件部は上書きされていく
	//fmt.Println("Rule21", Rule21)

	// [ルール22] 歩行距離:多2 年令:壮年2
	Rule22 := min_2(Walk_More.func_X(dis), Age_Common.func_X(age))
	Complain_More.func_Max(Rule22) // 後件部は上書きされていく
	//fmt.Println("Rule22", Rule22)

	// [ルール23] 歩行距離:多2 年令:高齢3
	Rule23 := min_2(Walk_More.func_X(dis), Age_More.func_X(age))
	Complain_MoreMore.func_Max(Rule23) // 後件部は上書きされていく
	//fmt.Println("Rule23", Rule23)

	// [ルール24] 歩行距離:多2 年令:老齢4
	Rule24 := min_2(Walk_More.func_X(dis), Age_MoreMore.func_X(age))
	Complain_MoreMore.func_Max(Rule24) // 後件部は上書きされていく
	//fmt.Println("Rule24", Rule24)

	// 推論計算
	numerator :=
		Complain_LessLess.func_X()*Complain_LessLess.func_Y() +
			Complain_Less.func_X()*Complain_Less.func_Y() +
			Complain_Common.func_X()*Complain_Common.func_Y() +
			Complain_More.func_X()*Complain_More.func_Y() +
			Complain_MoreMore.func_X()*Complain_MoreMore.func_Y()

	denominator :=
		Complain_LessLess.func_Y() +
			Complain_Less.func_Y() +
			Complain_Common.func_Y() +
			Complain_More.func_Y() +
			Complain_MoreMore.func_Y()

	complain := numerator / denominator

	return complain

}